dart_frog
dart_frog copied to clipboard
fix: middlewares wont work with dynamic routes
Description
Middlewares inside dynamic routes are not recognized.
Steps To Reproduce
- Create a frog server with the following route structure
routes/
- _middleware.dart
- [id]/
- index.dart
- _middleware.dart
- On the root middleware, put the following content:
import 'package:dart_frog/dart_frog.dart';
Handler middleware(Handler handler) {
return handler
.use(provider<String>((context) {
return 'root middleware haha';
}));
}
- On the middleware under
/[id], put the following content:
import 'package:dart_frog/dart_frog.dart';
Handler middleware(Handler handler) {
return handler
.use(provider<String>((context) {
return 'id middleware hihi';
}));
}
- On
/[id]/index.dartput the following content:
import 'package:dart_frog/dart_frog.dart';
Response onRequest(RequestContext context) {
final thingy = context.read<String>();
return Response(body: 'result: $thingy');
}
- Start the server and go to
http://localhost:8080/someid - See the result:
result: root middleware haha
Expected Behavior
The handler at /[id]/index.dart should; receive a context with information for the closest middleware, not the root one.
Additional Context
Reproducible with the CLI version 0.0.2-dev.7
related to https://github.com/dart-lang/shelf/issues/250 and https://github.com/google/dart-neats/issues/40
Descoping from 0.1, moving to 1.0