Skip to content

Commit 657f978

Browse files
authored
feat: cors 설정 추가
1 parent ec73134 commit 657f978

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/com/oronaminc/join/member/security/SecurityConfig.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class SecurityConfig {
2323
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2424
return http
2525
.csrf(csrf -> csrf.disable())
26+
.cors(withDefaults())
2627
.authorizeHttpRequests(auth -> auth
2728
.requestMatchers(
2829
"/api/auth/guest",
@@ -49,4 +50,22 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4950
.logout(withDefaults())
5051
.build();
5152
}
53+
54+
@Bean
55+
public CorsConfigurationSource corsConfigurationSource() {
56+
CorsConfiguration configuration = new CorsConfiguration();
57+
configuration.setAllowedOrigins(
58+
Arrays.asList(
59+
"http://localhost:8080",
60+
"http://localhost:3000"
61+
)
62+
);
63+
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
64+
configuration.setAllowedHeaders(List.of("*"));
65+
configuration.setAllowCredentials(true);
66+
67+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
68+
source.registerCorsConfiguration("/**", configuration);
69+
return source;
70+
}
5271
}

0 commit comments

Comments
 (0)