-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathserver.dart
More file actions
31 lines (25 loc) · 966 Bytes
/
server.dart
File metadata and controls
31 lines (25 loc) · 966 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
import 'dart:io';
import 'package:celest_db_studio/celest_db_studio.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
Future<void> main(List<String> args) async {
final databaseUrl = Platform.environment['DATABASE_URL'];
if (databaseUrl == null) {
print('DATABASE_URL environment variable is not set.');
exit(1);
}
final authToken = Platform.environment['DATABASE_AUTH_TOKEN'];
final dbStudio = await CelestDbStudio.create(
databaseUri: Uri.parse(databaseUrl),
authToken: authToken,
);
final handler = Pipeline()
.addMiddleware(logRequests())
.addHandler(dbStudio.call);
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await serve(handler, InternetAddress.loopbackIPv4, port);
print('Server listening on http://localhost:${server.port}');
await ProcessSignal.sigint.watch().first;
print('Stopping server...');
await server.close(force: true);
}