Skip to content

Commit

Permalink
Merge pull request #146 from minseok1015/dev
Browse files Browse the repository at this point in the history
feat : cors url 추가
  • Loading branch information
minseok1015 authored Aug 19, 2024
2 parents aa54844 + b33cc48 commit 6e9e96b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/main/java/store/itpick/backend/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http
.csrf(AbstractHttpConfigurer::disable) // CSRF 보호 비활성화
.cors(withDefaults()) // CORS 설정 추가
// .cors(withDefaults()) // CORS 설정 추가
.formLogin(FormLoginConfigurer::disable) // 폼 로그인 비활성화
.sessionManagement(sessionManagement ->
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 관리 정책 설정
Expand All @@ -42,19 +42,19 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.build();
}

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("https://itpick.netlify.app");
config.addAllowedOrigin("http://localhost:3000");
config.addAllowedOrigin("http://localhost:5173");
config.addAllowedOrigin("https://localhost:5173");
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token", "Accept", "X-Requested-With"));
config.setExposedHeaders(Arrays.asList("Authorization", "location"));
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
// @Bean
// public CorsFilter corsFilter() {
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// CorsConfiguration config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("https://itpick.netlify.app");
// config.addAllowedOrigin("http://localhost:3000");
// config.addAllowedOrigin("http://localhost:5173");
// config.addAllowedOrigin("https://localhost:5173");
// config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
// config.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token", "Accept", "X-Requested-With"));
// config.setExposedHeaders(Arrays.asList("Authorization", "location"));
// source.registerCorsConfiguration("/**", config);
// return new CorsFilter(source);
// }
}
2 changes: 1 addition & 1 deletion src/main/java/store/itpick/backend/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
public void addCorsMappings(CorsRegistry registry) {
log.info("CorsMapping이 호출 되었습니다.");
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000", "http://localhost:5173", "https://localhost:5173", "https://itpick.netlify.app","https://itpick.vercel.app","https://deploy-preview-107--itpick.netlify.app","https://deploy-preview-85--itpick.netlify.app","https://deploy-preview-99--itpick.netlify.app")
.allowedOrigins("http://localhost:3000", "http://localhost:5173", "https://localhost:5173", "https://itpick.netlify.app","https://itpick.vercel.app","https://deploy-preview-107--itpick.netlify.app","https://deploy-preview-85--itpick.netlify.app","https://deploy-preview-99--itpick.netlify.app","https://deploy-preview-129--itpick.netlify.app")
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH","OPTIONS")
.exposedHeaders("location", "Authorization")
.allowedHeaders("Content-Type", "Authorization", "X-Requested-With", "Accept")
Expand Down

0 comments on commit 6e9e96b

Please sign in to comment.