Skip to content

Commit

Permalink
[FIX] CORS 처리 Nginx 위임
Browse files Browse the repository at this point in the history
  • Loading branch information
yummygyudon committed Dec 2, 2024
1 parent fdb86ed commit 6988e58
Showing 1 changed file with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.List;

@RequiredArgsConstructor
@EnableWebSecurity
@Configuration
Expand Down Expand Up @@ -59,8 +61,9 @@ private void setHttp(HttpSecurity http) throws Exception {
http.httpBasic().disable()
.csrf().disable()
.formLogin().disable()
.cors().configurationSource(corsConfigurationSource())
.and()
.cors().disable()
// .cors().configurationSource(corsConfigurationSource())
// .and()
.authorizeHttpRequests(authorizeHttpRequests ->
authorizeHttpRequests
.requestMatchers(new AntPathRequestMatcher(AUTH_PATH_PATTERN)).permitAll()
Expand All @@ -74,21 +77,32 @@ private void setHttp(HttpSecurity http) throws Exception {
.addFilterBefore(jwtExceptionFilter, JwtAuthenticationFilter.class);
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
val configuration = new CorsConfiguration();

configuration.addAllowedOrigin(valueConfig.getADMIN_PROD_URL());
configuration.addAllowedOrigin(valueConfig.getADMIN_DEV_URL());
configuration.addAllowedOrigin(valueConfig.getADMIN_LOCAL_URL());
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*");
configuration.setAllowCredentials(true);

val source = new UrlBasedCorsConfigurationSource();

source.registerCorsConfiguration("/**", configuration);

return source;
}
// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// val configuration = new CorsConfiguration();
// configuration.setAllowedOrigins(List.of(
// valueConfig.getADMIN_PROD_URL(),
// valueConfig.getADMIN_DEV_URL(),
// valueConfig.getADMIN_LOCAL_URL()
// ));
// configuration.setAllowedMethods(List.of("HEAD", "GET", "POST", "PUT", "DELETE", "OPTIONS"));
// configuration.setAllowedHeaders(List.of(
// "Authorization",
// "Cache-Control",
// "Content-Type",
// "Accept"));
// configuration.setExposedHeaders(List.of("Authorization","Set-Cookie"));
//// configuration.addAllowedOrigin(valueConfig.getADMIN_PROD_URL());
//// configuration.addAllowedOrigin(valueConfig.getADMIN_DEV_URL());
//// configuration.addAllowedOrigin(valueConfig.getADMIN_LOCAL_URL());
//// configuration.addAllowedHeader("*");
//// configuration.addAllowedMethod("*");
// configuration.setAllowCredentials(true);
//
// val source = new UrlBasedCorsConfigurationSource();
//
// source.registerCorsConfiguration("/**", configuration);
//
// return source;
// }
}

0 comments on commit 6988e58

Please sign in to comment.