简体   繁体   English

Swagger UI 路由给出 404 未找到错误 - NestJs Swagger 模块

[英]Swagger UI route giving 404 Not found error - NestJs Swagger Module

On my localhost, swagger-ui document API route is working fine - http:://localhost:3000/api.在我的本地主机上,swagger-ui 文档 API 路由工作正常 - http:://localhost:3000/api。

But, when I deployed the nestjs build on server (AWS with Apache server), the same route is not working.但是,当我在服务器(带有 Apache 服务器的 AWS)上部署 nestjs 构建时,相同的路由不起作用。

In nestjs "main.ts" file, following code is written to initialize swagger.在nestjs“main.ts”文件中,写了如下代码初始化swagger。

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';


    async function bootstrap() {
      const app = await NestFactory.create(AppModule);
      app.enableCors();
    
      const config = new DocumentBuilder()
        .setTitle('Digital Health')
        .setDescription('Digital Health API')
        .setVersion('1.0')
        .build();
      const document = SwaggerModule.createDocument(app, config);
      SwaggerModule.setup('api', app, document);
    
      await app.listen(4000);
    }
    bootstrap();

I'm getting this error, when I hit the backend API url to access swagger documentation.当我点击后端 API url 访问 swagger 文档时,出现了这个错误。

在此处输入图像描述

Please try this way: and also clear the server cache :请尝试这种方式:并清除服务器缓存:

const document = SwaggerModule.createDocument(app, config);
 SwaggerModule.setup("api", app, document, {
 swaggerOptions: { defaultModelsExpandDepth: -1 },

Increase the memory of your lambda function and it should work增加你的 lambda function 的 memory 它应该可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM