在我的项目中,所有 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)