-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.dart
More file actions
33 lines (27 loc) · 780 Bytes
/
main.dart
File metadata and controls
33 lines (27 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'dart:convert';
import 'dart:io';
class Version {
final String version;
Version({required this.version});
Map<String, dynamic> toJson() => {
'version': version,
};
}
Future<void> main() async {
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8000);
print('listening on localhost:${server.port}');
final version = Version(version: '1.0.0');
await for (HttpRequest request in server) {
if (request.method == 'GET' && request.uri.path == '/version') {
request.response
..headers.contentType = ContentType.json
..write(jsonEncode(version))
..close();
} else {
request.response
..statusCode = HttpStatus.notFound
..write('Not Found')
..close();
}
}
}