Skip to content

Commit

Permalink
cors 개방
Browse files Browse the repository at this point in the history
  • Loading branch information
asn6878 committed Jun 3, 2024
1 parent 4ccf270 commit 00fc9bb
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -67,7 +69,7 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
return httpSecurity.build();
}

@Bean
/* @Bean
CorsConfigurationSource corsConfigurationSource() { // Localhost 환경 cors
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(corsOrigins);
Expand All @@ -76,6 +78,17 @@ CorsConfigurationSource corsConfigurationSource() { // Localhost 환경 cors
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}*/

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Collections.singletonList("*")); // 모든 출처 허용
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); // 모든 HTTP 메서드 허용
configuration.setAllowedHeaders(Collections.singletonList("*")); // 모든 헤더 허용
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

/*AntPathRequestMatcher를 사용하면 추후 메소드 설정 등 더 유연한 경로를 매칭할 수 있다.*/
Expand Down

0 comments on commit 00fc9bb

Please sign in to comment.