1. NestJS cors 설정
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// 모든 도메인의 요청 허용
app.enableCors();
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
NestJS에서 CORS(Cross-Origin Resource Sharing)를 설정하는
가장 간단한 방법은 main.ts 파일에서 설정합니다.
app.enableCors(); 로 모든 도메인에서의 요청을 허용합니다.
세부적으로 설정하려면 이렇게 합니다.
app.enableCors({
origin: 'http://localhost:3000', // 또는 ['http://localhost:3000', 'https://example.com']
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
});'NestJS' 카테고리의 다른 글
| [NestJS] NestJS WSL 배포하기 (0) | 2025.05.29 |
|---|---|
| [NestJS] NestJS DB연결하기 (1) | 2025.05.28 |
| [NestJS] NestJS 시작하기 (1) | 2025.05.28 |