Skip to content

Commit 8675a7a

Browse files
committed
fix: CORS 에러 해결
- allowedOrigin에서 allowedOriginPatterns으로 변경
1 parent 63c3b84 commit 8675a7a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/org/dfbf/soundlink/global/config/WebConfig.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
@Configuration
88
public class WebConfig implements WebMvcConfigurer {
9-
// private static final String DEVELOP_FRONT_ADDRESS = "http://localhost:3000";
10-
//
9+
/**
10+
* 스프링부트 5.3 이후,
11+
* allowCredentials가 true일 때, allowedOrigins에 특수 값인 "*" 추가할 수 없게 되었다.
12+
* 대신 allowOriginPatterns를 사용해야 한다.
13+
*/
14+
15+
private static final String DEVELOP_FRONT_ADDRESS = "http://localhost:3000";
16+
17+
// Main에 적용
1118
// @Override
1219
// public void addCorsMappings(CorsRegistry registry) {
1320
// registry.addMapping("/**")
@@ -18,13 +25,14 @@ public class WebConfig implements WebMvcConfigurer {
1825
// .allowCredentials(true);
1926
// }
2027

28+
// Develop에 적용
2129
@Override
2230
public void addCorsMappings(CorsRegistry registry) {
2331
registry.addMapping("/**") // 모든 엔드포인트
24-
.allowedOrigins("*") // 모든 도메인 허용
32+
.allowedOriginPatterns("*") // 모든 도메인 허용
2533
.allowedMethods("*") // 모든 HTTP 메서드 허용
2634
.allowedHeaders("*") // 모든 헤더 허용
2735
.exposedHeaders("*") // 모든 응답 헤더 허용
28-
.allowCredentials(false); // 인증 정보는 제외
36+
.allowCredentials(true); // 인증 정보는 제외
2937
}
3038
}

0 commit comments

Comments
 (0)