Rhythm
Rhythm

Reputation: 61

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.

But, when I deployed the nestjs build on server (AWS with Apache server), the same route is not working.

In nestjs "main.ts" file, following code is written to initialize 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.

enter image description here

Upvotes: 2

Views: 3277

Answers (2)

Thales
Thales

Reputation: 1

Increase the memory of your lambda function and it should work

Upvotes: -1

rohit choudhary
rohit choudhary

Reputation: 1

Please try this way! and also clear the server cache :

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

Upvotes: 0

Related Questions