Refactor database layer: convert to DatabaseProvider class with initialization
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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/user_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 userRoutes = UserRoutes(database);
|
||||
final geoRoutes = GeoRoutes(database);
|
||||
|
||||
final router = Router()
|
||||
..mount('', authRoutes.routes.call)
|
||||
..mount('', userRoutes.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}');
|
||||
}
|
||||
Reference in New Issue
Block a user