Global prefix

To set a prefix for every route registered in an HTTP application, use the setGlobalPrefix() method of the INestApplication instance.

  1. const app = await NestFactory.create(AppModule);
  2. app.setGlobalPrefix('v1');

You can exclude routes from the global prefix using the following construction:

  1. app.setGlobalPrefix('v1', {
  2. exclude: [{ path: 'health', method: RequestMethod.GET }],
  3. });

Alternatively, you can specify route as a string (it will apply to every request method):

  1. app.setGlobalPrefix('v1', { exclude: ['cats'] });