Skip to content

fix: CORS 제약 조건을 완화#10

Merged
MU-Software merged 1 commit intomainfrom
fix/relieve-cors
May 18, 2025
Merged

fix: CORS 제약 조건을 완화#10
MU-Software merged 1 commit intomainfrom
fix/relieve-cors

Conversation

@MU-Software
Copy link
Member

주요 변경 사항

  • CORS 이슈로 프론트에서 백엔드 호출을 못하고 있습니다.
    이를 CORS 설정을 완화해서 해소합니다.

추가 사항

"http://2025.pycon.kr",
f"{protocol}://{domain}{port}"
for protocol in ("http", "https")
for domain in ("localhost", "127.0.0.1", "pycon.kr", "local.dev.pycon.kr")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p5]
"local.dev.pycon.kr"로 입력하면 local과 dev가 합쳐진 "local.dev.pycon.kr" 도메인이 될 것 같은데, 저는 "local.pycon.kr"과 "dev.pycon.kr" 도메인이 따로 있다고 알고 있었어서 코멘트 남겨봅니다!
만약 제가 잘못 알았거나 local.dev.pycon.kr을 의도하신 게 맞다면 패스해주심 감사하겠습니다:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 의도한 것이 맞슴다, 로컬에서 프론트엔드 dev 서버를 돌릴 시 모든 기능을 전부 테스트하려면 https://local.dev.pycon.kr 도메인을 사용해야 해요! (프론트엔드에 그렇게 정의해뒀어요ㅎㅎ)

이렇게 하는 이유는, python-korea-payment 프로젝트에서 쿠키가 아래의 속성을 가지거든요.

  • secure=true
  • domain=pycon.kr (스테이징은 dev.pycon.kr)

이때, 프론트에서 Django의 CSRF 토큰을 위해 스테이징 cookie를 접근해야 했는데요, 프론트는 아래 조건에서만 쿠키에 접근할 수 있었어요.

  • 프론트의 도메인이 https여야 한다. (secure=true로 인해)
  • dev.pycon.kr 하위의 도메인이어야 한다. (domain을 지정해줬으므로)

그래서 로컬에서 프론트엔드 dev 서버를 띄울때 기존 PyCon의 도메인들과 겹치지 않으면서 로컬에서 /etc/hosts 파일에 등록해서 사용할 수 있는 안전한 도메인을 선정하다보니 https://local.dev.pycon.kr가 나온 것입니다!

그런데 이렇게 프론트엔드 dev 서버를 띄우니 https://rest-api.dev.pycon.kr 로 요청을 보내려 하니 CORS가 뜨더라고요 🫠
그래서 요기에 추가해주는 겁니다ㅎㅎ

@MU-Software MU-Software merged commit 7a8fe03 into main May 18, 2025
1 check passed
@MU-Software MU-Software deleted the fix/relieve-cors branch May 18, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants