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

Unsupported route path warning produced from app.setGlobalPrefix() #14513

Closed
3 of 15 tasks
0xHendrix opened this issue Jan 24, 2025 · 6 comments
Closed
3 of 15 tasks

Unsupported route path warning produced from app.setGlobalPrefix() #14513

0xHendrix opened this issue Jan 24, 2025 · 6 comments
Labels
needs triage This issue has not been looked into

Comments

@0xHendrix
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Setting a global prefix in Nest.js 11 produces the following warning:

Unsupported route path: "/v1/*". 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... {"context":"LegacyRouteConverter"}
const app = await NestFactory.create(AppModule, { bufferLogs: true, rawBody: true });
app.setGlobalPrefix("/v1");

When I remove app.setGlobalPrefix("/v1") the warning goes away.

Minimum reproduction code

N/A

Steps to reproduce

Include a global prefix in your main.ts file:

const app = await NestFactory.create(AppModule, { bufferLogs: true, rawBody: true });
app.setGlobalPrefix("/v1");

Expected behavior

No warnings appear from setting a global prefix

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

11.0.5

Packages versions

[System Information]
OS Version : macOS24.3.0
NodeJS Version : v22.11.0
NPM Version : 10.9.0

[Nest CLI]
Nest CLI Version : 11.0.2

[Nest Platform Information
platform-express version : 11.0.5
microservices version : 11.0.5
schematics version : 11.0.0
passport version : 11.0.5
schedule version : 5.0.1
graphql version : 13.0.2
swagger version : 11.0.3
testing version : 11.0.5
apollo version : 13.0.2
common version : 11.0.5
config version : 4.0.0
axios version : 4.0.0
bull version : 11.0.1
core version : 11.0.5
cqrs version : 11.0.0
cli version : 11.0.2

Node.js version

22.11.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@0xHendrix 0xHendrix added the needs triage This issue has not been looked into label Jan 24, 2025
@micalevisk
Copy link
Member

micalevisk commented Jan 24, 2025

I didn't manage to reproduce it here on Linux.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {bufferLogs:true,rawBody:true});
  app.setGlobalPrefix("/v1");
  await app.listen(process.env.PORT || 3000);
}
bootstrap();
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';

@Module({
  controllers: [AppController]
})
export class AppModule {}
import { Controller, Get } from '@nestjs/common';

@Controller()
export class AppController {
  @Get()
  foo() {
      return 1
  }
}

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

@micalevisk
Copy link
Member

make sure you've read the migration guide

I only got that warning when using @Get("*"), which is expected.

@micalevisk micalevisk closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
@krlkm
Copy link

krlkm commented Jan 27, 2025

In my case, I have something like this:

  configure(consumer: MiddlewareConsumer) {
    consumer.apply(SomeMiddleware).forRoutes('*');
  }

So, /v1/* will trigger this warning.
Updating it to '*path' will fix the problem.

@susanta96
Copy link

Can you share any way that I can resolve this ?? Same issue I am gettting too many warning

configure(consumer:` MiddlewareConsumer) {
  consumer.apply(LoggerMiddleware).forRoutes('*');
}

@ikdi
Copy link

ikdi commented Jan 31, 2025

I have the same problem as @0xHendrix when use app.setGlobalPrefix

@kamilmysliwiec
Copy link
Member

Just change * to {*path} as suggested in the migration guide https://docs.nestjs.com/migration-guide#express-v5

@nestjs nestjs locked and limited conversation to collaborators Jan 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

6 participants