I'm running into a strange problem with the Swagger interface on my NestJS server, which is hosted on a Windows Server environment and managed by PM2. While all other endpoints work fine over HTTP, the Swagger interface can only be accessed via HTTPS. Since I am connecting to the server through VPN and don't necessarily need HTTPS, I would like to access Swagger over HTTP instead.
I have set up the Swagger configuration in the main.ts file of my NestJS application.
I'm not sure what steps I should take or where I might have made a mistake. Any help you can provide would be greatly appreciated!
Recently, I've been experiencing an issue with the Swagger interface on my NestJS server. It functions perfectly when accessed locally, but fails to load when accessed over a VPN connection. Interestingly enough, all other endpoints work as expected over the VPN, except for Swagger.
Below is a snippet from my main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ConfigService } from '@nestjs/config';
import helmet from 'helmet';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
// security
app.enableCors({
origin: configService.get('CORS_ORIGIN'),
credentials: true,
});
app.use(helmet());
const swaggerConfig = new DocumentBuilder()
.setTitle('Logo Api')
.setDescription('TCS Logo Api Documentation')
.setVersion('1.0.0')
.addBearerAuth(
{
description: `Please enter token in following format: Bearer <JWT>`,
name: 'Authorization',
bearerFormat: 'Bearer',
scheme: 'Bearer',
type: 'http',
in: 'Header'
},
'access-token',
)
.build()
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('api', app, swaggerDocument);
await app.listen(configService.get('PORT'));
}
bootstrap();