feat: refactor server with shelf_static, return JSON responses, add API docs
This commit is contained in:
+10
-3
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user