-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix(#64): cors 적용 에러 #65
Merged
The head ref may contain hidden characters: "fix/#64-cors-\uC801\uC6A9-\uC5D0\uB7EC"
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
jaknaeso-server/src/main/java/org/nexters/jaknaesoserver/config/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.nexters.jaknaesoserver.config; | ||
|
||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
|
||
private static final String LOCAL_URL = "http://localhost:3000"; | ||
private static final String JAKNAESO_WEB_VERCEL_APP = "https://jaknaeso-web.vercel.app"; | ||
|
||
@Value("${cors.origins.api-doc}") | ||
private String API_DOC_HOST; | ||
|
||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
|
||
final CorsConfiguration corsConfiguration = new CorsConfiguration(); | ||
corsConfiguration.setAllowedOrigins(List.of(API_DOC_HOST, LOCAL_URL, JAKNAESO_WEB_VERCEL_APP)); | ||
corsConfiguration.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE")); | ||
corsConfiguration.addAllowedHeader("*"); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", corsConfiguration); | ||
return source; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
jaknaeso-server/src/main/java/org/nexters/jaknaesoserver/config/WebMvcConfig.java
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이건 그냥 궁금해서 물어보는건데 제가 공식문서를 제대로 읽은건지 모르겠는데..기존 세팅에서
쓰면 저희 Mvc 설정 따라가는걸까요 ??
https://docs.spring.io/spring-security/reference/servlet/integrations/cors.html
해당문서참고했습니다 ! PR머지 후 확인해봐도 될것같습니다
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.
넵 감사합니다! 확인해볼게요!
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.
민혁님 말씀이 맞는 것 같아요.
withDefaults()
를 MVC 설정을 따라가는 것 같습니다. 이 메소드를 사용했으면 더 빨리 해결할 수 있었겠네요. 다만CorsConfigurationSource
를 사용하면 조금 더 세밀한 설정이 가능하다는 장점이 있어서CorsConfigurationSource
를 사용하는 게 좋다고 생각해요.ex) API 엔드포인트별로 서로 다른 CORS 제어가 가능