No 'Access-Control-Allow-Origin'
플러터에서 nestjs에 요청 시 cors 정책에 의해 차단되어 요청에 대한 응답이 통과하지 않았습니다
그럼 리소스를 요청할 수 있도록 cors를 설정하기 위해 main.ts로 이동합니다
const app = await NestFactory.create(AppModule);
app.enableCors();
await app.listen(3000);
cors를 활성하려면 enableCors()를 nest 애플리케이션 객체에서 메서드를 호출하면 끝!
이렇게 하면 모든 도메인에 대해 리소를 요청할 수 있기 떄문에
특정 도메인 뿐만 아니라 특정 메서드 등 옵션을 줄 수 있습니다
app.enableCors({
origin: 'http://example1.com',
methods: ['GET,POST'],
});
[참고]
https://docs.nestjs.com/security/cors
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac
docs.nestjs.com
https://github.com/expressjs/cors
GitHub - expressjs/cors: Node.js CORS middleware
Node.js CORS middleware. Contribute to expressjs/cors development by creating an account on GitHub.
github.com
'IT > 기록' 카테고리의 다른 글
Docker에서 GitLab 설치해보기 (0) | 2022.10.25 |
---|---|
[Gmail] 특정 보낸 사람 메일이 프로모션 수신함으로 자동 분류 (0) | 2022.10.20 |
[Flutter] ClipRRect Widget - 이미지 테두리를 둥글게 만들고 싶을 때 (0) | 2022.10.14 |
우분투 Jenkins 설치하기 (0) | 2022.08.12 |
[Flutter] Firebase Authentication을 사용하여 구글 계정 인증하기 (0) | 2022.08.10 |