dart-neats
dart-neats copied to clipboard
Update Route.mount to accept handler
To add a middleware on the router, you need a pipeline which is an type of handler. But currently you can only use routers for a mount: The shelf_router.Route.mount annotation can only be used on a getter that returns shelf_router.Router (https://github.com/google/dart-neats/blob/6c1d4685b1598d22e829109276bf4fb7d585535a/shelf_router_generator/lib/src/shelf_router_generator.dart#L298).
It would be awesome if https://github.com/google/dart-neats/blob/6c1d4685b1598d22e829109276bf4fb7d585535a/shelf_router_generator/lib/src/shelf_router_generator.dart#L32 accepts Handler, like the method in shelf_router: https://github.com/google/dart-neats/blob/6c1d4685b1598d22e829109276bf4fb7d585535a/shelf_router/lib/src/router.dart#L149
Should I create a pull request?
okay, i think it's too much for me, isAssignableFrom doesn't work with function typedefs
@jonasfj What do you think?
Let's first determine if we want this in shelf_router, then make a solution in shelf_router_generator.
How is this different from using Router.all? And is not likely that we're going to want something more like router.middleware(...)?
The difference between Router.all and Router.mount is, that Router.mount removes the path of the router before. For example, you have the path /auth/sign-in, the Router.all gives the full path instead of only /sign-in at Router.mount.
I saw the sourecode and shelf_router already supports a normal handler: https://github.com/google/dart-neats/blob/6c1d4685b1598d22e829109276bf4fb7d585535a/shelf_router/lib/src/router.dart#L149
I can see the point that allowing the shelf_router.Route.mount to wrap a Handler wouldn't be so bad :smile:
Especially, when we already have the support in shelf_router, it wouldn't be a breaking change, it just means tweaking the code-generator to accept both Router and Handler. I think I'm down with that!
I think we should do this, since it only affects the code-generator. @CodeDoctorDE, if you want to take a stab at I'm happy to reviews.
Whether or not this is the best way to add middleware is a good question, we can discuss that in https://github.com/google/dart-neats/issues/32
It would be awesome. You only need to wrap the router in a pipeline and have the route.mount annotation. I think I cannot contribute because I haven't much experience by making code generators. I'm stuck at the point where I want to check if the return type is a handler
Any updates?
No update, this is labeled as an enhancement. I don't think it's critical, if someone does I'm willing to help with code reviews.
But as far as I'm aware nobody is working on this.