Esc*_*890 1 nginx node.js jenkins docker nestjs
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CoreConfig } from './config.const';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestApplicationOptions } from '@nestjs/common';
async function bootstrap() {
const httpOptions ={
requestCert: false,
rejectUnauthorized: true,
};
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.addServer(`http://localhost:${CoreConfig.app.port}`)
.setTitle('test UI/AI')
.setDescription('UI meta service')
.setVersion('1.0')
.addTag('test')
.addBearerAuth({type:'http', bearerFormat: 'authorization'})
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('docs', app, document);
app.enableCors();
app.setGlobalPrefix('ui');
await app.listen(CoreConfig.app.port);
}
bootstrap().then();
Run Code Online (Sandbox Code Playgroud)
当我的应用程序使用 nginx 部署时,我们有一个前缀用于路由到此 NestJs 应用程序(UI),所有请求均以 404 结尾,但在本地一切正常。
这是实例部署的结果
{"statusCode":404,"error":"Not Found","message":"Cannot GET /ui/"}
Run Code Online (Sandbox Code Playgroud)
小智 6
我配置了 ingress-nginx 将所有访问流量发送/api/
到我的后端(NestJS 应用程序)。
问题是该/api/
部件被发送到我的 NestJS 应用程序,但这些路由都不存在。例如,我的 graphql 端点位于/graphl
但使用 ingress-nginx 所有流量都会被发送到/api/graphql
404'ing。
对我来说,解决方法是在 NestJS 中添加“api”的全局前缀,并手动将 graphql 路径设置为/api/graphql
.
您也可以使用 ingress-nginx 重写来删除通过ingress-nginx 重写目标/api/
发送到后端的路由
归档时间: |
|
查看次数: |
2200 次 |
最近记录: |