Created
October 27, 2018 21:50
-
-
Save clarkezone/d99f1653bb58e3fb6016db05cfc8fb16 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:async'; | |
import 'dart:io'; | |
import 'package:http_server/http_server.dart'; | |
void main() { | |
var webFiles = new VirtualDirectory('web'); | |
runZoned(() { | |
HttpServer.bind('0.0.0.0', 8080).then((server) { | |
server.listen((request) { | |
if (request.uri.path == '/') { | |
request.response.redirect(request.uri.resolve('/index.html')); | |
} else if (request.uri.path == '/version') { | |
request.response.headers..contentType = ContentType.TEXT; | |
request.response | |
..writeln('Dart version: ${Platform.version}') | |
..writeln('Dart executable: ${Platform.executable}') | |
..writeln('Dart executable arguments: ' | |
'${Platform.executableArguments}') | |
..close(); | |
} else { | |
webFiles.serveRequest(request); | |
} | |
}); | |
}); | |
}, | |
onError: (e, stackTrace) { | |
print('Error processing request $e\n$stackTrace'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment