diff --git a/src/main/java/goorm/reinput/global/security/CorsConfig.java b/src/main/java/goorm/reinput/global/security/CorsConfig.java index d81e744..262615e 100644 --- a/src/main/java/goorm/reinput/global/security/CorsConfig.java +++ b/src/main/java/goorm/reinput/global/security/CorsConfig.java @@ -1,24 +1,26 @@ package goorm.reinput.global.security; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.util.pattern.PathPatternParser; +import java.util.Arrays; @Configuration -public class CorsConfig implements WebMvcConfigurer { +public class CorsConfig { - // TODO: cors 설정. dev, prod 주소 추가 예정 -// @Value("${cors.origin.development}") -// private String developmentOrigin; -// -// @Value("${cors.origin.production}") -// private String productionOrigin; + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowedOriginPatterns(Arrays.asList("http://192.168.0.*")); + config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD")); + config.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type")); + config.setAllowCredentials(true); - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedMethods("OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE") - .allowCredentials(true) - .allowedOrigins("http://localhost:3000","https://2024-beotkkotthon-team-24-fe.vercel.app", "https://reinput.info", "https://www.reinput.info"); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); + source.registerCorsConfiguration("/**", config); + return source; } } \ No newline at end of file