Skip to content

docs(faq): document multiple global prefixes - #3531

Draft
micalevisk wants to merge 1 commit into
nestjs:masterfrom
micalevisk:docs/multiple-global-prefixes
Draft

docs(faq): document multiple global prefixes#3531
micalevisk wants to merge 1 commit into
nestjs:masterfrom
micalevisk:docs/multiple-global-prefixes

Conversation

@micalevisk

Copy link
Copy Markdown
Member

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: nestjs/nest#16095

The global prefix FAQ only shows a single string prefix. Regex prefixes like '(prefixOne|prefixTwo)' stopped working in v11, and the docs don't mention an alternative.

What is the new behavior?

Documents the array form of setGlobalPrefix() added in nestjs/nest#17713:

  • app.setGlobalPrefix(['api', 'v1']) registers every route under each prefix, and a hint presents it as the replacement for regex prefixes.
  • exclude works with multiple prefixes: excluded routes are served without any prefix.
  • A warning that @nestjs/swagger only reads the first prefix, both in the generated document and for useGlobalPrefix.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This is a draft until nestjs/nest#17713 is merged and released. After that, the page could say which version added array support.

How the content was checked:

  • The documented behavior was confirmed with a temporary integration test against feat(core): add support for array of global prefixes nest#17713, on Express and Fastify: routes and middleware respond under each prefix, and excluded routes respond only without a prefix.
  • The Swagger warning is based on lib/utils/get-global-prefix.ts in nestjs/swagger, which calls getGlobalPrefix() and so only gets the first prefix.
  • npm run docs-only generated all 136 docs, with no unmatched-link warnings from this page.

nestjs/nest#17713 lets `setGlobalPrefix()` accept an array of prefixes,
replacing the regex prefixes that stopped working in v11
(nestjs/nest#16095). Document the array form, how `exclude` applies to
every prefix, and that `@nestjs/swagger` only reads the first prefix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant