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.