Skip to content

Commit

Permalink
fix: 허용할 Origin 설정 후 CORS 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
khee2 committed Jul 25, 2024
1 parent 2ba9ca6 commit 46f2206
Showing 1 changed file with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public class SecurityConfig {
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;

private final Environment env;

/**
* SecurityConfig 생성자 - 필수 구성 요소 주입
*
Expand All @@ -45,12 +43,10 @@ public class SecurityConfig {
public SecurityConfig(
JwtTokenProvider jwtTokenProvider,
JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint,
JwtAccessDeniedHandler jwtAccessDeniedHandler,
Environment env) {
JwtAccessDeniedHandler jwtAccessDeniedHandler) {
this.jwtTokenProvider = jwtTokenProvider;
this.jwtAuthenticationEntryPoint = jwtAuthenticationEntryPoint;
this.jwtAccessDeniedHandler = jwtAccessDeniedHandler;
this.env = env;
}

/**
Expand Down Expand Up @@ -108,17 +104,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

// 환경 변수에서 허용할 Origin을 설정
String allowedOrigins = env.getProperty("allowed.origins");
// log.info("Allowed Origins: " + allowedOrigins); // 허용할 Origin 값 출력
if (allowedOrigins != null) {
String[] origins = allowedOrigins.split(",");
for (String origin : origins) {
// log.info("Adding allowed origin: " + origin.trim());
configuration.addAllowedOrigin(origin.trim());
}
}
configuration.addAllowedOrigin("http://localhost:3000");
configuration.addAllowedOrigin("http://3.36.150.194:8080");
configuration.addAllowedMethod("*");
configuration.addAllowedHeader("*");
configuration.setAllowCredentials(true);
Expand Down

0 comments on commit 46f2206

Please sign in to comment.