-
-
Notifications
You must be signed in to change notification settings - Fork 8k
feat(core): exclude route from global prefix #5291
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
feat(core): exclude route from global prefix #5291
Conversation
New global prefix option to exclude some routes as a string or a RouteInfo
26b41f6
to
47f05de
Compare
Pull Request Test Coverage Report for Build 1a449be6-ea80-4e4c-87fd-c417f3816f9e
💛 - Coveralls |
app = module.createNestApplication(); | ||
}); | ||
|
||
it.only(`should use the global prefix`, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are all of these it.only
? Shouldn't they bet just it()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I forgot to remove them after testing
import { AppModule } from '../src/app.module'; | ||
import * as request from 'supertest'; | ||
import { RequestMethod } from '@nestjs/common/enums/request-method.enum' | ||
describe('Global prefix', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add one more test showing that RequestMethod.GET
works as described?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I just added the test you asked and found out it wasn't working correctly with RequestMethod.GET
because it's the enum 0 so I changed a line in the code as well. Now everything should be working (I hope)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I think some more test cases should be added.
- Testing wildcard behaviour
- Testing exclude:cats as string and request GET /cats/foo and GET /api/v1/cats/foo
- Testing using a middleware to make sure its not being effected
For now I am exploring the repo from mobile, so I decide to write a comment
Looks like the failing test is due to a package installation problem. Other than that, to me, it's looking good. Let's wait to hear from Kamil too 😸 |
Is this PR going to be merged at some point? |
this looks like a great feature to have |
Thank you so much, it is one of long-awaited features of Nest.js. What do you think about testing whether a nested path can be excluded? Like so: app.setGlobalPrefix('v1', { exclude: [
{ path: '/health/heartbeat', method: RequestMethod.GET }
]}); |
LGTM, thanks! This will be added in 8.0.0 |
New global prefix option to exclude some routes as a string or a RouteInfo
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
You can specify a global route prefix but you can't exclude some routes
Issue Number: #963
What is the new behavior?
It add a new option object for the global prefix. You can exclude routes based on the path and the request method
You can also specify route as a string (it apply on every request method) or a mix of the 2 like so:
This is my first contribution to this awesome framework and there are probably things that need to be improved or moved so please give me some feedback.
I followed the syntax proposed in the issue (back in 2018) and I tried to follow the middleware route exclude code.
I would like to add support for wildcard parameters (like
'cats/(.*)'
) the same way it's done for the middleware but maybe it's better to do it step by step and create another PR ?I can also write the doc for this if you want
Does this PR introduce a breaking change?
Other information
Have a great day