Skip to content

Commit

Permalink
Update main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueweiand committed Mar 7, 2024
1 parent 4719ca0 commit d9fd28f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
const configService = app.get(EnvService)
const port = configService.get('PORT')

function getSwaggerServerUrl() {
switch (process.env.NODE_ENV) {
case 'production':
return 'https://nestjs-ecommerce-alpha.vercel.app/api';
default:
return `http://localhost:${port}/api`;
}
}

const app = await NestFactory.create(AppModule, {
snapshot: true,
rawBody: true,
})

const configService = app.get(EnvService)
const port = configService.get('PORT')

app.useGlobalPipes(new ValidationPipe({
transform: true,
whitelist: true,
Expand All @@ -21,6 +30,7 @@ async function bootstrap() {
const config = new DocumentBuilder()
.setTitle('API')
.setVersion('0.1')
.addServer(getSwaggerServerUrl())
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
Expand Down

0 comments on commit d9fd28f

Please sign in to comment.