36 lines
1.0 KiB
Dart
36 lines
1.0 KiB
Dart
import 'dart:io';
|
|
import 'dart:async';
|
|
|
|
import 'package:shelf/shelf.dart';
|
|
import 'package:shelf/shelf_io.dart';
|
|
import 'package:shelf_router/shelf_router.dart';
|
|
|
|
import 'database/database_provider.dart';
|
|
import 'routes/auth_routes.dart';
|
|
import 'routes/geo_routes.dart';
|
|
|
|
void main(List<String> args) async {
|
|
final database = DatabaseProvider();
|
|
await database.initialize();
|
|
|
|
Timer.periodic(const Duration(minutes: 5), (timer) {
|
|
database.cleanupExpired();
|
|
});
|
|
|
|
final authRoutes = AuthRoutes(database);
|
|
final geoRoutes = GeoRoutes(database);
|
|
|
|
final router = Router()
|
|
..mount('', authRoutes.routes.call)
|
|
..mount('', geoRoutes.routes.call)
|
|
..get('/', (Request req) => Response.ok('Family Safety Tracker API\n'));
|
|
|
|
final handler = Pipeline()
|
|
.addMiddleware(logRequests())
|
|
.addHandler(router.call);
|
|
|
|
final ip = InternetAddress.anyIPv4;
|
|
final port = int.parse(Platform.environment['PORT'] ?? '8080');
|
|
final server = await serve(handler, ip, port);
|
|
print('Server listening on port ${server.port}');
|
|
} |