Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Fix outdated mini_file_server.dart #61

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions httpserver/bin/mini_file_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ var targetFile =
File(p.join(p.dirname(Platform.script.toFilePath()), 'index.html'));

Future main() async {
var server;
Stream<HttpRequest> server;

try {
server = await HttpServer.bind(InternetAddress.loopbackIPv4, 4044);
} catch (e) {
print("Couldn't bind to port 4044: $e");
print('Could not bind to port 4044: $e');
exit(-1);
}
print('Listening on http://${server.address.address}:${server.port}/');
stevenanthonyrevo marked this conversation as resolved.
Show resolved Hide resolved
print('Listening on ${InternetAddress.loopbackIPv4.address}:4044');

await for (HttpRequest req in server) {
if (await targetFile.exists()) {
print("Serving ${targetFile.path}.");
print('Serving ${targetFile.path}.');
req.response.headers.contentType = ContentType.html;
try {
await req.response.addStream(targetFile.openRead());
} catch (e) {
print("Couldn't read file: $e");
print('Could not read file: $e');
exit(-1);
}
} else {
print("Can't open ${targetFile.path}.");
print('Could not open ${targetFile.path}.');
req.response.statusCode = HttpStatus.notFound;
}
await req.response.close();
await req.response.close();
}
}