Error endpoit request

Robson Kretzmann 20 Reputation points
2024-10-24T01:48:23.3566667+00:00

Hello, I created a node API with nest but I'm having problems accessing the endpoints after publishing it on the webapp via code, it always returns

Cannot GET /swagger

Does anyone know what settings I need to make for it to work?

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
79 questions
{count} votes

Accepted answer
  1. Shree Hima Bindu Maganti 1,585 Reputation points Microsoft Vendor
    2024-10-24T05:38:40.87+00:00

    Hi @Robson Kretzmann,

    welcome to the Microsoft Q&A Platform!

    To fix the Cannot GET /swagger error in your NestJS application after deployment, can you cross check with your main.ts file

    Ensure Swagger is set up in main.ts: Make sure you have the following Swagger setup in your main.ts file:

    import { NestFactory } from '@nestjs/core';
    import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
    import { AppModule } from './app.module';
    async function bootstrap() {
      const app = await NestFactory.create(AppModule);
      const config = new DocumentBuilder()
        .setTitle('API Docs')
        .setDescription('API description')
        .setVersion('1.0')
        .build();
      const document = SwaggerModule.createDocument(app, config);
      SwaggerModule.setup('swagger', app, document); // URL: /swagger
      await app.listen(process.env.PORT || 3000); // Ensure correct port is used
    }
    bootstrap();
    

    Deploy the API with this setup: Redeploy your NestJS API ensuring the above SwaggerModule.setup('swagger', ...) is included in main.ts.

    Access the Swagger URL: After deployment, access https://your-domain/swagger to see your API documentation.

    This will resolve your Cannot GET /swagger

    If the answer is helpful, please click "Accept Answer" and kindly upvote it.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.