You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would propose to add middleware support in the shelf_router_generator. Currently, to use the router_generator with middleware, you can write something like this:
This creates a lot of repetitive and boilerplate code for a routine (and quite frequent) action (the use of middleware). This code could be generated automatically.
Possible solution design
I see 2 possible paths:
Add a Middleware Annotation (similar to the one described here Add middleware for handlers #338)
In this case, the above code would look something like this:
@Middleware(logging)
@Middleware(authorization)
@Route.get('/user/<userId>')
Future<Response> getUser(Request request, String userId) async {
// do something with request and userId variables
}
Add an annotation to the Route constructor parameter List<Middleware> middlewares
In this case, code would look something like this:
@Route.get('/user/<userId>' middlewares: [logging, authorization])
Future<Response> getUser(Request request, String userId) async {
// do something with request and userId variables
}
The generated code could look something like this in both cases (such a construct is necessary to preserve the passing of the PATH parameters to the client handler):
I believe the second solution (with the middlewares parameter) is more successful and I could attempt to make the necessary changes and create a pull request myself.
Is this a good idea?
The text was updated successfully, but these errors were encountered:
Motivation
I would propose to add middleware support in the shelf_router_generator. Currently, to use the router_generator with middleware, you can write something like this:
This creates a lot of repetitive and boilerplate code for a routine (and quite frequent) action (the use of middleware). This code could be generated automatically.
Possible solution design
I see 2 possible paths:
Add a Middleware Annotation (similar to the one described here Add middleware for handlers #338)
In this case, the above code would look something like this:
Add an annotation to the Route constructor parameter
List<Middleware> middlewares
In this case, code would look something like this:
The generated code could look something like this in both cases (such a construct is necessary to preserve the passing of the PATH parameters to the client handler):
I believe the second solution (with the
middlewares
parameter) is more successful and I could attempt to make the necessary changes and create a pull request myself.Is this a good idea?
The text was updated successfully, but these errors were encountered: