Middleware forRoutes path matching inconsistent for RequestMethod.ALL and other RequestMethods
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Not sure if it is intended behaviour, but it seems that path matching works differently for RequestMethod.ALL
and other methods eg. RequestMethod.POST
.
Expected behavior
Path matching is same for any of RequestMethod
.
Minimal reproduction of the problem with instructions
Example module with middleware:
export class GatewayModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(FilterMiddleware)
.forRoutes(
{ path: '/v1/users', method: RequestMethod.ALL },
{ path: '/v2/users', method: RequestMethod.POST }
);
}
}
For method RequestMethod.ALL
both urls will match and be handled by middleware:
/v1/users
- ok
/v1/users/123
- ok
For method RequestMethod.{POST,PUT,DELETE,GET,...}
only first variant is matched handled by middleware:
/v1/users
- ok
/v1/users/123
- not matched
To get same behaviour for ALL and the other request method, wildcards has to be used for non ALL request methods (eg. /v2/users**
). This is not a huge problem, but I see this inconsistency something that is worth fixing.
What is the motivation / use case for changing the behavior?
I would like to build http proxy where proxying can be done to different servers based on request method.
Eg. configuration of a proxy (example for brevity may not make sense, posting here just to express the idea)
[
{
"path": ["/v1/users"],
"target": "http://localhost:3003",
"method": "DELETE"
},
{
"path": ["/v2/users"],
"target": "http://localhost:3001",
"method": "ALL"
},
]
Environment
Nest version: 5.6.2
For Tooling issues:
- Node version: 10.15.3
- Platform: macOS
Others:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:8 (2 by maintainers)
Probably a stupid question buy I’ll ask it anyway: Why doesn’t
@All
/RequestMethod.ALL
map toapp.all()
instead ofapp.use()
?Let’s track this here https://github.com/nestjs/nest/pull/6237