Repository navigation
docs(versioning): say when middleware is scoped to a version - #3691
Merged
kamilmysliwiec merged 1 commit intoNov 2, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?
Issue Number: N/A
The Middleware versioning section says that
forRoutes({ path: 'cats', method: RequestMethod.GET, version: '2' })applies the middleware only to version'2'of/cats, and that this works with any versioning type. That's only true for URI versioning, where the version is part of the path the middleware is mounted on (route-info-path-extractor.ts#L272-L274). With header, media type or custom versioning, all versions share the same path, so the middleware runs for version'1'requests too. The same goes for binding it to a controller withversion: '2'. This was kept on purpose in nestjs/nest#18276.I checked it on master (cabdedf10) with Express, Fastify and the node adapter. With URI versioning the middleware only runs for v2, with the other three types it runs for both v1 and v2.
What is the new behavior?
The sentence now only makes that claim for URI versioning, and a notice says that with the other types the middleware runs for every version of the path. It points to guards and interceptors for code that should run for one version only, since they run on the handler the router picked. A guard and an interceptor on the v2 controller only ran for v2 requests with header, media type and custom versioning, on all three adapters.
Does this PR introduce a breaking change?
Other information