Skip to content

Conversation

@GabrielMochi
Copy link

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.

image

Changes

Code Enhancements

  • Introduced useLegacyWildcardRoute in the Params interface to allow users to toggle between /{*splat} and * wildcard route formats.
  • Updated LoggerModule configuration:
    • Uses /{*splat} as the default wildcard route (NestJS 11+).
    • Falls back to * if useLegacyWildcardRoute is enabled (NestJS 10 and below).
  • Refactored 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 of path-to-regexp now 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

  • Added unit tests in __tests__/use-legacy-wildcard-route.spec.ts to verify that LoggerModule correctly applies the wildcard route configuration.
image

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-pino

For users running an earlier version of NestJS 11, updating the nestjs-pino library with this change will require setting useLegacyWildcardRoute: true to ensure that pino-http logs 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, set useLegacyWildcardRoute: true in the module options:

LoggerModule.forRoot({ useLegacyWildcardRoute: true });

Checklist

  • Code changes tested
  • Documentation updated
  • No breaking changes introduced

- Add new `useLegacyWildcardRoute` option to provide backward compatibility
- Update default route pattern from `*` to `/{*splat}` for newer NestJS versions
- Document the new configuration option in README.md
- Maintain backward compatibility for projects using older NestJS versions
@invaderb
Copy link

any update on getting this merged in?

@fakhir-shad
Copy link

Can we get this merged

@invaderb
Copy link

invaderb commented Nov 7, 2025

@GabrielMochi can you merge the latest changes in your branch to catch it up?

@iamolegga Can we please get this merged? it's been open for 8 months

@mlz11
Copy link

mlz11 commented Nov 21, 2025

Hi @iamolegga 👋

We're using nestjs-pino with NestJS 11 and setGlobalPrefix(), and encountering the LegacyRouteConverter warning that this PR addresses.

Is there anything blocking this PR from being merged? I'd be happy to help.

Thanks!

@iamolegga
Copy link
Owner

Sorry for the long delay.

This PR introduces a breaking change. Correct me if I'm wrong but the current implementation cannot be shipped as a new minor change without breaking the support of older nestjs versions. If so, this could be merged and shipped only in the new major version of current lib.

With this being said I would like to clarify my plans to pin new major releases of this lib to new major versions of nestjs with keeping support of only two latest versions of nestjs. So when we ship a new major version of this lib nestjs@11 will be oldest version to support, and we could simply update the DEFAULT_ROUTES const, and as a result this PR is not relevant.


Option two is keeping usage of existing routes by default without breaking routing for users of older nestjs and express (what about fastify?) versions, and introduce a new options' field to use new routing when set to true.

Moreover I was thinking if it's possible to parse package.json/lock-file and check which versions are used and choose the correct routing underhood, or is it too hard? This is not a mandatory anyway.

If this option will be chosen I would like new test cases to be updated and show that warning log is hidden with this new feature turned on (or appeared in case of deprecated routing).

Wdyt?

@invaderb
Copy link

@iamolegga doesn't the optional parameter (useLegacyWildcardRoute) not satisfy compatibility with previous versions, if following semver that should satisfy the minor requirements

MINOR version when you add functionality in a backward compatible manner

@iamolegga
Copy link
Owner

@invaderb it forces everyone with older NestJS version to set this new optional parameter to true, which is a breaking change

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.

5 participants