Skip to content

fix: middlewares wont work with dynamic routes #136

@renancaraujo

Description

@renancaraujo

Description

Middlewares inside dynamic routes are not recognized.

Steps To Reproduce

  1. Create a frog server with the following route structure
routes/
  - _middleware.dart
  - [id]/
    - index.dart
    - _middleware.dart
  1. 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';
  }));
}
  1. 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';
  }));
}
  1. On /[id]/index.dart put the following content:
import 'package:dart_frog/dart_frog.dart';

Response onRequest(RequestContext context) {
  final thingy = context.read<String>();
  return Response(body: 'result: $thingy');
}
  1. Start the server and go to http://localhost:8080/someid
  2. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working as expected

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions