CORS

김듑듑·2022년 7월 31일

아주 사람 킹받게함
난 다 죽어도 이거 풀리 이해못할듯

https://docs.aws.amazon.com/ko_kr/apigateway/latest/developerguide/how-to-cors.html
https://ko.javascript.info/fetch-crossorigin
https://developer.mozilla.org/ko/docs/Web/HTTP/CORS

CORS : Cross-Origin Resource Sharing

  • CORS는 브라우저에서 실행 중인 스크립트에서 시작되는 cross-origin HTTP 요청을 제한하는 브라우저 보안 기능
  • REST API의 리소스가 비 단순 cross-origin HTTP 요청을 받을 경우 CORS 지원을 활성화해야함.
  • Cross-Origin Request를 보내려면 Cross-Origin에서 받은 특별한 헤더가 필요함👈이러한 정책이 CORS

이 경우에 CORS가 발생하는데

  1. 다른 도메인(예: example.com에서 amazondomains.com으로)
  2. 다른 하위 도메인(예: example.com에서 petstore.example.com으로)
  3. 다른 포트(예: example.com에서 example.com:10777으로)
  4. 다른 프로토콜(예: https://example.com에서 http://example.com으로)

내경우는 다른 프로토콜 https에서 http를 요청하는 경우였다...


그럼 Mixed Content는 뭔댕

Mixed Content는 크롬이랑 파폭에서 HTTP 콘텐츠랑 HTTPS 콘텐츠가 섞였을때 띄우는 경고 👉 전부 HTTPS로 수정하면 해결완



그럼 프론트가 시도해볼수 있는 CORS 해결방법은?

제일 처음에 Access-Control-Allow-Origin로 해결해 본다
안되면 proxy 설정해서 우회해본다ㄱ-

(+)난 express 서버 만들어서 두 방법 다 써서 해결보다가 시간없어서 그냥 기능을 수정함...하핫



그냥 localhost https로 바꿔서 개발한다

지금 상황 : http에서 https 주소의 이미지 가져와야함
당연히 cors로 빠꾸먹음

blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

인증서만드는 방법 mkcert, openssl, minica
날로먹는방법
https://yongbin.kim/2019/12/02/https-for-localhost-with-minica.html
https://brewagebear.github.io/https-apply-localhost/

0개의 댓글