Global prefix for a module / route tree
See original GitHub issueHi,
there is an older issue, which got implemented: https://github.com/nestjs/nest/issues/40 - allowing to
setGlobalPrefix('api')
on the app instance.
This is a very neat feature and since I’m looking to create some sort of a “route tree”, it would be great to set some “route extending strategy”.
Say I want to create a route tree like this: -> api (from app.setGlobalPrefix) –> /users (UsersModule with prefix ‘users’ for all of it’s ‘children’ modules and controllers) —> /posts (PostsModule with prefix ‘posts’ for all of it’s ‘children’ modules and controllers) ----> /comments (Now I could declare a CommentsController with route ‘comments’ and this controller’s route would be composed from all of the ancestors above, in this case: ‘api/users/posts/comments’ ----> /upvotes (this one would then be ‘api/users/posts/upvotes’)
that means I’d like to somehow set the ‘module route prefix’ for all of it’s children’s modules & controllers.
If there’s already a way to achieve this, please point me in the right direction, otherwise it would be pretty nice to have this.
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:41 (30 by maintainers)
@VinceOPS This is how we’ve done it so far
I’ve opened a PR. This is sort of what we’re talking about, but in a more nest-friendly way. My intended usage is like this:
Essentially, at runtime, it reflects the parent module’s paths back onto each controller.