Created
August 2, 2020 01:50
-
-
Save guilherme-v/d18f3964774d78f937c2d5f97a409506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: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