admin管理员组文章数量:1410730
Everything works fine on local machine. The problem arises after deployment.
After deployment, /querybuilder
gets appended to the base url.
So,
http://localhost:80/helloworld
would bee
.139/querybuilder/helloworld
Swagger page at:
.139/querybuilder/swagger/
When I execute a method through swagger ui page: This is what I see in networks tab:
Request URL: .139/
Controller:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
Main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('Query Builder - MongoDb Parser')
.setDescription("This is Query Builder's MongoDb Parser takes database agnostic queries and transpiles it into native MongoDb query.")
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
await app.listen(80);
}
bootstrap();
Everything works fine on local machine. The problem arises after deployment.
After deployment, /querybuilder
gets appended to the base url.
So,
http://localhost:80/helloworld
would bee
http://52.xxx.xxx.139/querybuilder/helloworld
Swagger page at:
http://52.xxx.xxx.139/querybuilder/swagger/
When I execute a method through swagger ui page: This is what I see in networks tab:
Request URL: http://52.xxx.xxx.139/
Controller:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
Main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('Query Builder - MongoDb Parser')
.setDescription("This is Query Builder's MongoDb Parser takes database agnostic queries and transpiles it into native MongoDb query.")
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
await app.listen(80);
}
bootstrap();
Share
Improve this question
edited Sep 20, 2020 at 12:02
Sai Gummaluri
1,40410 silver badges17 bronze badges
asked Sep 18, 2020 at 10:31
SamuraiJackSamuraiJack
5,56918 gold badges103 silver badges212 bronze badges
1 Answer
Reset to default 8In most cases the most appropriate way to achieve this is by using setGlobalPrefix method which adds prefix to your API endpoints and URL used by swagger.
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('querybuilder');
However, if your routing is handled by external server (e.g. nginx), you can add the prefix only to the URL used by swagger using addServer
method.
const options = new DocumentBuilder()
.setTitle('Query Builder - MongoDb Parser')
.addServer('/querybuilder')
本文标签: javascriptNestJs swagger missing base pathStack Overflow
版权声明:本文标题:javascript - NestJs swagger missing base path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744321893a2600540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论