Skip to content

Commit 494d83a

Browse files
committed
refactor(core): rebuild root middleware to consume providers
Updates `routes/_middleware.dart` to reflect the new dependency injection architecture. The middleware now consumes the `Uuid` provider from the context to generate a request ID. The chain is simplified to apply only the essential global middleware: request ID generation, request logging, and error handling.
1 parent 03eca2d commit 494d83a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

routes/_middleware.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:dart_frog/dart_frog.dart';
22
import 'package:ht_api/src/middlewares/error_handler.dart';
3+
import 'package:ht_api/src/middlewares/request_logger.dart';
34
import 'package:uuid/uuid.dart';
45

56
// --- Request ID Wrapper ---
@@ -46,15 +47,18 @@ class RequestId {
4647

4748
// --- Middleware Definition ---
4849
Handler middleware(Handler handler) {
49-
// This middleware chain will be rebuilt in a later step.
50-
// For now, it only provides a request ID and basic error handling.
50+
// This is the root middleware chain for the entire API.
51+
// The order is important:
52+
// 1. Request ID: Assigns a unique ID to each request for tracing.
53+
// 2. Request Logger: Logs request and response details.
54+
// 3. Error Handler: Catches all errors and formats them into a standard
55+
// JSON response.
5156
return handler
5257
.use(
5358
(innerHandler) {
5459
return (context) {
55-
// In a later step, the Uuid instance will be provided from server.dart
56-
// For now, we create it here.
57-
const uuid = Uuid();
60+
// Read the singleton Uuid instance provided from server.dart.
61+
final uuid = context.read<Uuid>();
5862
final requestId = RequestId(uuid.v4());
5963
return innerHandler(context.provide<RequestId>(() => requestId));
6064
};

0 commit comments

Comments
 (0)