Created
May 18, 2019 09:26
-
-
Save eyelash/b90ce161872957b8dfcdead1b0768110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
String elem(String tag, String text) { | |
return '<$tag>$text</$tag>'; | |
} | |
String h1(String text) { | |
return elem('h1', text); | |
} | |
String p(String text) { | |
return elem('p', text); | |
} | |
Future runServer() async { | |
var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 4040); | |
await for (HttpRequest request in server) { | |
request.response.headers.contentType = ContentType.html; | |
request.response.write(h1('Hello, world!')); | |
request.response.write(p(request.uri.path)); | |
request.response.close(); | |
} | |
} | |
runServerSync() { | |
HttpServer.bind(InternetAddress.loopbackIPv4, 4040).then((server) { | |
server.listen((request) { | |
request.response.headers.contentType = ContentType.html; | |
request.response.write(h1('Hello, world!')); | |
request.response.write(p(request.uri.path)); | |
request.response.close(); | |
}); | |
}); | |
} | |
Future main(List<String> arguments) async { | |
await runServer(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment