Skip to content

docs(versioning): say when middleware is scoped to a version - #3691

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
OmBhandwaldar:docs/versioning-middleware
Nov 2, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
OmBhandwaldar:docs/versioning-middleware

Conversation

@OmBhandwaldar

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

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 with version: '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?

  • Yes
  • No

Other information

@kamilmysliwiec
kamilmysliwiec merged commit b5939d7 into nestjs:master Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants