-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: 프론트 새 도메인 CORS 설정 추가 #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @yeongsinkeem, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 백엔드 애플리케이션이 새로운 프론트엔드 도메인으로부터의 요청을 올바르게 처리할 수 있도록 CORS(Cross-Origin Resource Sharing) 설정을 업데이트합니다. 이는 프론트엔드 서비스의 확장 또는 변경에 따라 필요한 조치입니다. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
이 PR은 CORS 설정을 수정하여 프론트엔드 새 도메인을 추가하는 것을 목적으로 하고 있습니다. 실제 변경 사항은 허용된 출처 목록의 순서를 변경한 것입니다.
코드 리뷰에서는 CORS 설정과 관련된 두 가지 개선 사항을 제안했습니다.
Origin헤더 표준에 따라 중복되고 불필요할 수 있는 URL(뒤에/가 붙는)을 제거하여 설정을 명확히 할 것을 제안합니다.- 유지보수성 향상을 위해 하드코딩된 URL 목록을
application.properties와 같은 외부 설정 파일로 옮기는 것을 권장합니다.
이러한 변경 사항을 적용하면 CORS 설정을 더 안전하고 유연하게 관리할 수 있을 것입니다.
| CorsConfiguration configuration = new CorsConfiguration(); | ||
| configuration.setAllowedOriginPatterns(Arrays.asList( | ||
| "http://localhost:3005", "https://frontend-tackit.vercel.app/", "https://frontend-tackit.vercel.app", | ||
| "http://localhost:3005", "https://frontend-tackit.vercel.app", "https://frontend-tackit.vercel.app/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RFC 6454에 따르면 Origin 헤더는 스킴, 호스트, 포트로 구성되며 경로(path)를 포함하지 않습니다. 따라서 Origin 헤더 값은 https://frontend-tackit.vercel.app과 같은 형태이며, 일반적으로 마지막에 슬래시(/)가 붙지 않습니다.
"https://frontend-tackit.vercel.app/" 설정은 중복일 가능성이 높으므로, 제거하여 코드를 더 명확하게 하고 잠재적인 문제를 방지하는 것이 좋습니다.
| "http://localhost:3005", "https://frontend-tackit.vercel.app", "https://frontend-tackit.vercel.app/", | |
| "http://localhost:3005", "https://frontend-tackit.vercel.app", |
| configuration.setAllowedOriginPatterns(Arrays.asList( | ||
| "http://localhost:3005", "https://frontend-tackit.vercel.app/", "https://frontend-tackit.vercel.app", | ||
| "http://localhost:3005", "https://frontend-tackit.vercel.app", "https://frontend-tackit.vercel.app/", | ||
| "https://www.tackit.site" | ||
| )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS 허용 출처(origin) 목록을 코드에 하드코딩하는 대신, application.properties 또는 application.yml 같은 외부 설정 파일로 분리하는 것을 고려해보세요. 이렇게 하면 애플리케이션을 다시 빌드하고 배포하지 않고도 허용 출처를 쉽게 변경할 수 있어 유연성과 유지보수성이 향상됩니다.
예를 들어, application.properties에 다음과 같이 설정할 수 있습니다:
cors.allowed-origins=http://localhost:3005,https://frontend-tackit.vercel.app,https://www.tackit.site그리고 SecurityConfig 클래스에서 @Value 어노테이션을 사용하여 이 값을 주입받을 수 있습니다:
@Value("${cors.allowed-origins}")
private List<String> allowedOrigins;
// ...
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(allowedOrigins);
// ...
}이렇게 하면 Arrays.asList() 호출 없이 더 깔끔하게 코드를 작성할 수 있습니다.
이슈 번호
작업 내용