nest
nest copied to clipboard
fix(core): prevent exclude method from overwriting previous calls
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
Issue Number: N/A
Summary:
Previously, calling multiple exclude method in MiddlewareConsumer overwrote the previously excluded routes.
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(MIDDLEWARE_VALUE))
.exclude('test', 'overview/:id', 'wildcard/(.*)', {
path: 'middleware',
method: RequestMethod.POST,
}) // ignored
.exclude('multiple/exclude')
.forRoutes('*');
}
It only worked well when using a single exclude method.
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(MIDDLEWARE_VALUE))
.exclude('test', 'overview/:id', 'wildcard/(.*)', 'multiple/exclude', {
path: 'middleware',
method: RequestMethod.POST,
})
.forRoutes('*');
}
I created a minimum reproduction repository.
Both repositories contain the same code. You can review the test code (exclude-middleware.spec.ts) and see the results by cloning or forking the repository and running npm run test.
What is the new behavior?
This change ensures that the exclude method appends new routes to the existing excluded routes list instead of overwriting them.
This preserves all previous exclude calls and maintains the intended behavior of accumulating excluded routes.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Pull Request Test Coverage Report for Build 5967bb56-11c2-444f-9474-e996881d3e45
Details
- 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 92.124%
| Totals | |
|---|---|
| Change from base Build 94cfa8c0-2cff-488c-b4b7-6f54fde1b9de: | 0.0% |
| Covered Lines: | 6737 |
| Relevant Lines: | 7313 |
💛 - Coveralls
Can not use terminal to sudo
Hello @ajlchiban,
Thank you for your response. Did you mean that you couldn't use the terminal to run sudo commands in the CodeSandbox? I thought anyone could use the terminal to sudo by forking the public project.
To avoid any confusion, I've added a minimum reproduction repository on GitHub as well.
lgtm