简体   繁体   English

setGlobalPrefix 排除端点 nestjs

[英]setGlobalPrefix exclude endpoint nestjs

In my project all the APIs are prefixed with /payments .在我的项目中,所有 API 都以/payments为前缀。 Now I want some of my APIs not to be prefixed with this.现在我希望我的一些 API 不以这个为前缀。

In my main.ts to set global prefix I've used.在我的main.ts中设置我使用过的全局前缀。

app.setGlobalPrefix('payments');

Some solution similar to middleware would be cleaner.一些类似于中间件的解决方案会更干净。

export class AppModule implements NestModule {
  constructor(private configService: ConfigService) { }
  public configure(consumer: MiddlewareConsumer) {
    if (this.configService.get('REQUIRE_AUTH') !== 'FALSE') {
      consumer
        .apply(AuthMiddleware)
        .exclude({
          path: 'platform/healthcheck',
          method: RequestMethod.ALL,
        })
        // Like this
    }
  }
}

You can pass the second parameter to setGlobalPrefix method which is an object, that would contain the property exclude and that type should be an array.您可以将第二个参数传递给 setGlobalPrefix 方法,它是一个 object,它将包含属性exclude并且该类型应该是一个数组。 Define the route names in that array.在该数组中定义路由名称。 and that routes will be excluded from the prefix并且路由将从前缀中排除

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

To see more about the setGlobalPrefix method check the below link要查看有关 setGlobalPrefix 方法的更多信息,请查看以下链接

https://docs.nestjs.com/faq/global-prefix https://docs.nestjs.com/faq/global-prefix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM