Nestjs setGlobalPrefix exclude option not working

58 Views Asked by At

All my routes should have api prefix, except the .well-known route so I've added that path into the exclude option of the setGlobalPrefix method

  app.setGlobalPrefix('api', { exclude: ['.well-known'] });

I've also tried to add it like this

  app.setGlobalPrefix('api', { exclude: [{ path: '.well-known', method: RequestMethod.GET }] });

But it still works only works with API prefix

With api prefix

Without api prefix

Here is my controller

@Controller('.well-known')
export class WellKnownController {
  constructor(
    @Inject(
    CustomProviders.APPLE_APP_SITE_ASSOCIATION)
    private readonly appleAppSiteAssociationFile: object,
  ) {}

  @Get('apple-app-site-association')
  async getAppleAppSiteAssociation() {
    return this.appleAppSiteAssociationFile;
  }
}
1

There are 1 best solutions below

1
Yusuf Umut Bulak On

Exclude does not work because it cannot match the path value in the route. The problem is solved when you make it the same as your path in the route as in the code block below.

main.ts file

app.setGlobalPrefix('api', {
    exclude: [
      {
        path: '.well-known/apple-app-site-association',
        method: RequestMethod.GET,
      },
    ],
  });