Skip to content

Commit

Permalink
Merge pull request #12 from potenday-project/develop
Browse files Browse the repository at this point in the history
http://localhost:3000 도메인 허용
  • Loading branch information
HwangHoYoon authored Dec 14, 2023
2 parents 87db1ff + 04bed42 commit 52d75c1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/chwipoClova/common/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 52d75c1

Please sign in to comment.