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
+4 -3
View File
@@ -1,6 +1,7 @@
import 'package:shelf/shelf.dart';
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
import 'package:dotenv/dotenv.dart';
import 'dart:convert';
class AuthMiddleware {
final Future<Response> Function(Request, String) handler;
@@ -11,7 +12,7 @@ class AuthMiddleware {
final authorization = request.headers['authorization'];
if (authorization == null || !authorization.startsWith('Bearer ')) {
return Response(401, body: 'Authorization header missing or invalid');
return Response(401, body: jsonEncode({'error': 'Authorization header missing or invalid'}), headers: {'Content-Type': 'application/json'});
}
final token = authorization.substring(7);
@@ -25,9 +26,9 @@ class AuthMiddleware {
return handler(request, login);
} on JWTExpiredException {
return Response(401, body: 'Token expired');
return Response(401, body: jsonEncode({'error': 'Token expired'}), headers: {'Content-Type': 'application/json'});
} on JWTException {
return Response(401, body: 'Invalid token');
return Response(401, body: jsonEncode({'error': 'Invalid token'}), headers: {'Content-Type': 'application/json'});
}
}
}