Skip to content

Commit

Permalink
chore: allow CORS from vite server
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldahal committed May 21, 2024
1 parent 916ccc7 commit 7eacfcc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AppModule } from './app.module';
import setupSwagger from './docs/swagger';
import { NestFactory } from '@nestjs/core';
import { ConfigService } from '@nestjs/config';
import { ValidationPipe } from '@nestjs/common';
import { Redirect } from './middlewares/redirect.middleware';
import setupSwagger from './docs/swagger';
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand All @@ -22,6 +23,15 @@ async function bootstrap() {
// Swagger docs configuration
setupSwagger(app);

// Enable CORS
const corsOptions: CorsOptions = {
origin: 'http://localhost:5173',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
};

app.enableCors(corsOptions);

// .env configuration
const configService = app.get(ConfigService);
const port = configService.get<number>('PORT') || 8888;
Expand Down

0 comments on commit 7eacfcc

Please sign in to comment.