포디 Podi
또렷한 기억보다 글이 낫다
포디 Podi
  • 분류 전체보기 (83)
    • 책 (14)
      • 기록 (14)
      • 한줄 (0)
    • IT (62)
      • 기록 (61)
    • 일상 (5)
      • 음식 (0)
      • 기록 (5)
    • 게임 (0)
      • 몬스터헌터 (0)

블로그 메뉴

  • 홈으로
  • 방명록
  • 태그들
  • 깃허브
  • 유튜브
  • 인스타

공지사항

인기 글

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
포디 Podi

또렷한 기억보다 글이 낫다

Nest (NestJS) CORS 설정
IT/기록

Nest (NestJS) CORS 설정

2022. 10. 18. 23:12
728x90

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
    'IT/기록' 카테고리의 다른 글
    • Docker에서 GitLab 설치해보기
    • [Gmail] 특정 보낸 사람 메일이 프로모션 수신함으로 자동 분류
    • [Flutter] ClipRRect Widget - 이미지 테두리를 둥글게 만들고 싶을 때
    • 우분투 Jenkins 설치하기
    포디 Podi
    포디 Podi
    기록은 복리다

    티스토리툴바