Fix: Support for Express Wildcard Routes in NestJS 11 #2283
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.
Overview
This PR removes a warning in the console when running NestJS 11 due to deprecated wildcard routes (
*). It introduces an optional parameter (useLegacyWildcardRoute) to ensure compatibility with previous versions while using the new format required in NestJS 11.Changes
Code Enhancements
useLegacyWildcardRoutein theParamsinterface to allow users to toggle between/{*splat}and*wildcard route formats.LoggerModuleconfiguration:/{*splat}as the default wildcard route (NestJS 11+).*ifuseLegacyWildcardRouteis enabled (NestJS 10 and below).DEFAULT_ROUTES:DEFAULT_ROUTES: Uses/{*splat}for wildcard routes.LEGACY_DEFAULT_ROUTES: Uses*for wildcard routes.Fixes
Resolved the following NestJS 11 warning in the console:
"Unsupported route path:
/api/*. In previous versions, the symbols ?, *, and + were used to denote optional or repeating path parameters. The latest version ofpath-to-regexpnow requires the use of named parameters. For example, instead of using a route like/users/*to capture all routes starting with/users, you should use/users/*path. For more details, refer to the migration guide. Attempting to auto-convert..."Ensured compatibility with older versions using an optional flag.
Tests
__tests__/use-legacy-wildcard-route.spec.tsto verify thatLoggerModulecorrectly applies the wildcard route configuration.Why This Change?
With NestJS 11 deprecating the
*wildcard format in favor of/{*splat}, this update removes console warnings while ensuring compatibility with older NestJS versions.Important Note for Users Updating
nestjs-pinoFor users running an earlier version of NestJS 11, updating the
nestjs-pinolibrary with this change will require settinguseLegacyWildcardRoute: trueto ensure thatpino-httplogs incoming requests as expected. If this parameter is not specified, the application will continue to function correctly, but HTTP requests will not appear in the terminal logs.How to Use
By default, the library will use
/{*splat}for wildcard routes. To enable legacy behavior, setuseLegacyWildcardRoute: truein the module options:Checklist