小编Kau*_*dey的帖子

setGlobalPrefix 排除端点 Nestjs

在我的项目中,所有 API 都以/payments. 现在我希望我的一些 API 不带有此前缀。

在我main.ts设置的全局前缀中我使用过。

app.setGlobalPrefix('payments');
Run Code Online (Sandbox Code Playgroud)

一些类似于中间件的解决方案会更干净。

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
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript node.js nestjs

3
推荐指数
1
解决办法
2780
查看次数

标签 统计

javascript ×1

nestjs ×1

node.js ×1