dart_frog icon indicating copy to clipboard operation
dart_frog copied to clipboard

fix: middlewares wont work with dynamic routes

Open renancaraujo opened this issue 3 years ago • 2 comments

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

renancaraujo avatar Jul 04 '22 16:07 renancaraujo

related to https://github.com/dart-lang/shelf/issues/250 and https://github.com/google/dart-neats/issues/40

felangel avatar Jul 04 '22 20:07 felangel

Descoping from 0.1, moving to 1.0

BeatriceMitchell avatar Jul 28 '22 14:07 BeatriceMitchell