在本地计算机上一切正常。部署后出现问题。
部署后,/querybuilder
将附加到基本URL。
所以,
http://localhost:80/helloworld
将成为
http://52.xxx.xxx.139/querybuilder/helloworld
在以下位置翻动页面:
http://52.xxx.xxx.139/querybuilder/swagger/
当我通过swagger ui页面执行方法时: 这是我在“网络”标签中看到的:
控制器:
@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();
答案 0 :(得分:0)
在大多数情况下,最合适的方法是使用setGlobalPrefix方法,该方法将前缀添加到您的API端点和swagger使用的URL。
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('querybuilder');
但是,如果路由是由外部服务器(例如nginx)处理的,则可以使用addServer
方法将前缀仅添加到swagger使用的URL。
const options = new DocumentBuilder()
.setTitle('Query Builder - MongoDb Parser')
.addServer('/querybuilder')