-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Express Middleware not being called for some endpoints #13593
Comments
there is another configuration where it does not work: consumer.apply(someMiddleware)
.exclude('id')
.exclude('somethingelse') this works consumer.apply(someMiddleware)
.exclude('id', 'somethingelse') |
@satanshiro I guess that's another issue. Would you like to create a PR to fix that one? |
@AbanobNageh @micalevisk consumer
.apply(AppMiddleware)
.exclude({ path: '/:id(\\d+)', method: RequestMethod.GET })
.forRoutes(AppController); |
and @satanshiro this code works, too! consumer
.apply(AppMiddleware)
.exclude({ path: 'all', method: RequestMethod.GET })
.exclude({ path: '/:id(\\d+)', method: RequestMethod.GET })
.forRoutes(AppController); |
@micalevisk |
|
@EeeasyCode Thank you. However, How did you test this? The code you included doesn't work for me. I tried it on my reproduction repo above and the tests still fail. Also, my knowledge of Regex is lacking so excuse me if I am wrong but are you saying that for every path with a param (ex: |
I think I found the cause of the issue. When |
Is there an existing issue for this?
Current behavior
This issue happens when there are 2 endpoints:
/all
/:id
If the
/:id
endpoint is excluded from the middleware then the middleware is not called for both of the 2 endpoints.Minimum reproduction code
https://github.com/AbanobNageh/nestjs-middleware-exclude-issue
Steps to reproduce
The above repository has a middleware and the following endpoints:
/all
. The middleware should run for this endpoint./:id
. The middleware should not run for this endpoint.You can reproduce the issue by using the tests in the repository.
/all
endpoint test fails and the/:id
endpoint test succeeds when only the/:id
endpoint is excluded.Expected behavior
Only the excluded endpoints should be excluded from the middleware. The middleware should run for the
/all
endpoint and shouldn't run for the/:id
endpoint.Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
10.3.8
Packages versions
Node.js version
20.10.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: