Skip to content

Instantly share code, notes, and snippets.

@clarkezone
Created October 27, 2018 21:50
Show Gist options
  • Save clarkezone/d99f1653bb58e3fb6016db05cfc8fb16 to your computer and use it in GitHub Desktop.
Save clarkezone/d99f1653bb58e3fb6016db05cfc8fb16 to your computer and use it in GitHub Desktop.
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