Skip to content

Instantly share code, notes, and snippets.

@guilherme-v
Created August 2, 2020 01:50
Show Gist options
  • Save guilherme-v/d18f3964774d78f937c2d5f97a409506 to your computer and use it in GitHub Desktop.
Save guilherme-v/d18f3964774d78f937c2d5f97a409506 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'dart:io';
Future<void> main() async {
// We'll create a local server that will be listening for requests at port 8082
final server = await HttpServer.bind('127.0.0.1', 8082);
await for (HttpRequest req in server) {
// All requests will be logged into a local 'logs.tmp' file
final File file = File('./logs.tmp');
// Handle the requests and write them in the File
String content = await utf8.decoder.bind(req).join();
var data = "\n${content.replaceAll("\"", "")}";
file.writeAsStringSync(data, mode: FileMode.writeOnlyAppend);
// Answer back 200OK
req.response..statusCode = HttpStatus.ok;
await req.response.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment