Skip to main content

NestJS - CORS

  app.enableCors({
// origin: true,
origin: ['http://localhost:3000/'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});

add to main.ts

Full Source Code

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
// origin: true,
origin: ['http://localhost:3000/'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});
await app.listen(3000);
}

bootstrap();