feat: refactor server with shelf_static, return JSON responses, add API docs

This commit is contained in:
dmit.b
2026-05-09 09:12:44 +03:00
parent cd85f5f2db
commit 97db1b6b58
46 changed files with 172153 additions and 24 deletions
+10 -3
View File
@@ -4,6 +4,8 @@ import 'dart:async';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf_cors_headers/shelf_cors_headers.dart';
import 'package:shelf_static/shelf_static.dart';
import 'database/database_provider.dart';
import 'routes/auth_routes.dart';
@@ -22,12 +24,17 @@ void main(List<String> args) async {
final router = Router()
..mount('/', authRoutes.routes.call)
..mount('/', geoRoutes.routes.call)
..get('/', (Request req) => Response.ok('Family Safety Tracker API\n'));
..mount('/', geoRoutes.routes.call);
final staticHandler = createStaticHandler('web', defaultDocument: 'index.html');
final handler = Pipeline()
.addMiddleware(corsHeaders())
.addMiddleware(logRequests())
.addHandler(router.call);
.addHandler(Cascade()
.add(staticHandler)
.add(router.call)
.handler);
final ip = InternetAddress.anyIPv4;
final port = int.parse(Platform.environment['PORT'] ?? '9090');