41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:shelf/shelf.dart';
|
|
import 'package:shelf/shelf_io.dart' as shelf_io;
|
|
|
|
import '../lib/db.dart';
|
|
import '../lib/env.dart';
|
|
import '../lib/firebase_auth.dart';
|
|
import '../lib/handlers/profile_handler.dart';
|
|
|
|
Future<void> main() async {
|
|
final Directory serverRoot = Directory.current;
|
|
if (!File('migrations/001_users.sql').existsSync()) {
|
|
final String cwd = serverRoot.path;
|
|
stderr.writeln(
|
|
'Run the API from the server/ directory (cd server && dart run bin/server.dart). '
|
|
'Current directory: $cwd',
|
|
);
|
|
exit(1);
|
|
}
|
|
|
|
final ServerEnv env = ServerEnv.load();
|
|
final ProfileDb db = await ProfileDb.connect(env.databaseUrl);
|
|
await db.migrate();
|
|
|
|
final FirebaseAuthVerifier auth = FirebaseAuthVerifier(env.firebaseWebApiKey);
|
|
final Handler handler = Pipeline()
|
|
.addMiddleware(logRequests())
|
|
.addHandler(profileHandler(db: db, auth: auth));
|
|
|
|
final HttpServer server = await shelf_io.serve(
|
|
handler,
|
|
InternetAddress.anyIPv4,
|
|
env.port,
|
|
);
|
|
|
|
stdout.writeln(
|
|
'Cyber Hybrid Hub API listening on http://localhost:${server.port}',
|
|
);
|
|
}
|