Skip to content

Commit fa68a06

Browse files
committed
🐛 fix: CORS 설정 추가
1 parent be6fbc9 commit fa68a06

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.f1.backend.global.config;
2+
3+
import java.util.List;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.cors.CorsConfiguration;
7+
import org.springframework.web.cors.CorsConfigurationSource;
8+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
9+
10+
@Configuration
11+
public class CorsConfig {
12+
@Bean
13+
public CorsConfigurationSource corsConfigurationSource() {
14+
CorsConfiguration config = new CorsConfiguration();
15+
16+
config.setAllowedOrigins(List.of("http://localhost:3000", "http://brainrace.duckdns.org"));
17+
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
18+
config.setAllowedHeaders(List.of("*"));
19+
config.setAllowCredentials(true);
20+
21+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
22+
source.registerCorsConfiguration("/**", config);
23+
return source;
24+
}
25+
}

backend/src/main/java/io/f1/backend/global/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.springframework.context.annotation.Bean;
1313
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.security.config.Customizer;
1415
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1516
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1617
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
@@ -31,6 +32,7 @@ public class SecurityConfig {
3132
@Bean
3233
public SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
3334
http.csrf(AbstractHttpConfigurer::disable)
35+
.cors(Customizer.withDefaults())
3436
.exceptionHandling(
3537
exception ->
3638
exception.authenticationEntryPoint(customAuthenticationEntryPoint))

0 commit comments

Comments
 (0)