admin管理员组文章数量:1287803
In my project all the APIs are prefixed with /payments
. Now I want some of my APIs not to be prefixed with this.
In my main.ts
to set global prefix I've used.
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
}
}
}
In my project all the APIs are prefixed with /payments
. Now I want some of my APIs not to be prefixed with this.
In my main.ts
to set global prefix I've used.
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
}
}
}
Share
Improve this question
asked Dec 21, 2022 at 10:05
Kaushik KakdeyKaushik Kakdey
6736 silver badges11 bronze badges
2
- Instead of a global prefix you would have to set the prefix on the controller and then you can pick and choose what endpoints have it – mh377 Commented Dec 21, 2022 at 13:07
- Did you read the docs? – Jay McDoniel Commented Dec 21, 2022 at 15:48
1 Answer
Reset to default 12You 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. 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
https://docs.nestjs./faq/global-prefix
本文标签: javascriptsetGlobalPrefix exclude endpoint nestjsStack Overflow
版权声明:本文标题:javascript - setGlobalPrefix exclude endpoint nestjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741322173a2372266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论