diff --git a/src/main/java/com/chwipoClova/common/config/WebSecurityConfig.java b/src/main/java/com/chwipoClova/common/config/WebSecurityConfig.java index 1e93046..cc2431a 100644 --- a/src/main/java/com/chwipoClova/common/config/WebSecurityConfig.java +++ b/src/main/java/com/chwipoClova/common/config/WebSecurityConfig.java @@ -18,6 +18,12 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.servlet.config.annotation.CorsRegistry; + +import java.util.Arrays; @Configuration @EnableWebSecurity @@ -62,4 +68,20 @@ public SecurityFilterChain securityFilterChain(final @NotNull HttpSecurity http ; return http.build(); } + + @Bean + CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.addAllowedOrigin("http://localhost:3000"); + configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + configuration.setAllowCredentials(true); + configuration.setAllowedHeaders(Arrays.asList("Authorization", "Authorization-refresh", "Cache-Control", "Content-Type")); + + /* 응답 헤더 설정 추가*/ + configuration.setExposedHeaders(Arrays.asList("Authorization", "Authorization-refresh")); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } }