Skip to content
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

fix(core): Handle wildcard routes with global prefix #14627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PleBea
Copy link

@PleBea PleBea commented Feb 13, 2025

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
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When using a global prefix (via app.setGlobalPrefix()) in combination, NestJS throws an "Unsupported route path" warning. This is due to changes in the underlying path-to-regexp library, which now requires named parameters for wildcard routes.

What is the new behavior?

With this change, the warning message no longer appears when using app.setGlobalPrefix("/api") in combination with wildcard routes. Users can now use global prefixes and wildcard routes together without seeing the "Unsupported route path" warning.

Example:

app.setGlobalPrefix("/api");

This code now works as expected without any warnings.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kamilmysliwiec
Copy link
Member

Not sure if I'm following. Why would we want to drop the warning?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 651479c1-93e4-4126-b5fd-374131eeea16

Details

  • 1 of 2 (50.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 89.284%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/core/middleware/route-info-path-extractor.ts 1 2 50.0%
Totals Coverage Status
Change from base Build a7ea6842-aa6e-4263-9421-262d3598fd5d: -0.01%
Covered Lines: 7124
Relevant Lines: 7979

💛 - Coveralls

@PleBea
Copy link
Author

PleBea commented Feb 14, 2025

Not sure if I'm following. Why would we want to drop the warning?

The warning appears because when a user uses setGlobalPrefix, it internally appends "/*" to the prefix. This triggers the LegacyRouterConverter to output a warning suggesting the use of "/*path". However, Nest users who are correctly using setGlobalPrefix are still seeing this warning, even though they haven't directly used the wildcard syntax. Our attempt to remove the warning is to prevent confusion for users who are following Nest's recommended practices but still encountering this seemingly erroneous warning.

@kamilmysliwiec
Copy link
Member

it internally appends "/*" to the prefix

We should change that logic then instead of hiding the warning

@PleBea
Copy link
Author

PleBea commented Feb 14, 2025

it internally appends "/*" to the prefix

We should change that logic then instead of hiding the warning

You're right, changing the logic is a better solution.

I'll update the PR with these changes soon. Thanks for the feedback.

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.

3 participants