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
Middleware route exclusion behavior change when upgrading from 9.3.2 to 9.3.3 #11442
Comments
The versioning is added by Nest, so all "real" endpoints are in the format Of course, I am open to the possibility that I am doing this completely wrong, but at least with version 9.2.1 this seemed to work as I expected it. |
Just as a sanity check, does this still not work with the versioning removed? |
I only ask because, I have had issues with uri versioning before |
I tried now with v 9.4.0 with versioning removed, but no change - the Middleware is still applied. Removing the prefix entirely makes the exclusion work again. So it does seem like the prefix plays a part in this. |
Hi @adskragnar as you didn't shared any repro code, could you please checkout the changelog https://github.com/nestjs/nest/releases/tag/v9.3.0 to see if you find some change that could be related with your issue? It would help a lot :) PRs are more than welcomed as well. |
Thanks for the quick responses! First, apologies - I seem to have made a mistake in determining when the behavior changed - I believe the change occurred in between versions 9.3.2 -> 9.3.3. Looking through the changes from 9.3.2...9.3.3 lists the commit fix(core): add global prefix to exclude paths for middleware, which at least given the apparent connection from the issue to the global prefix looks to be interesting. Note that these are not listed as fixes when looking at the 9.3.3 release. |
@adskragnar thanks! That was a fix to this issue: #9990 Since you have enabled the global versioning with a default version, there's no What if you do this instead: app.setGlobalPrefix(globalPrefix, {
exclude: [{ path: '/v1/health', method: RequestMethod.GET }],
}); |
The Health Controller in this case is set up as For completeness, I also tried removing the global prefix exclusion for health (but leaving the prefix). This places the health endpoint at (All tests here conducted using version 9.3.3). |
This issue should be fixed in this PR #11650 |
Just for context, we also have just faced this issue. After updating from version Our previously working code:
After updating to
Summary: |
The issue still exists. |
Did you read the migration guide?
Is there an existing issue that is already proposing this?
Potential Commit/PR that introduced the regression
No response
NestJS version
9.2.1->9.3.0
Describe the regression
I have a
/health
path that is excluded from the global prefix. I also have some auth-related middleware that should be applied to all paths except the/health
endpoint. This worked fine up to version9.2.1
usingconsumer.apply(MyMiddleware).exclude('/health').forRoutes('*')
.When upgrading to version 9.3.0, the exclusion no longer works and the auth middleware is applied. I have also tried version 9.4.0 with the same result.
Minimum reproduction code
No response
Input code
In main:
in
app.module.ts
:Expected behavior
The middleware is not applied to requests for the
/health
path.Other
No response
The text was updated successfully, but these errors were encountered: