From b494361a1778b09d91e4f1487f18ffeff278dfe8 Mon Sep 17 00:00:00 2001 From: tori Date: Tue, 27 Feb 2024 00:00:30 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20CorsConfig=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hyundai/app/config/CorsConfig.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/hyundai/app/config/CorsConfig.java b/src/main/java/com/hyundai/app/config/CorsConfig.java index 6a5a20e..2c5cb1f 100644 --- a/src/main/java/com/hyundai/app/config/CorsConfig.java +++ b/src/main/java/com/hyundai/app/config/CorsConfig.java @@ -1,28 +1,30 @@ package com.hyundai.app.config; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author 황수영 * @since 2024/02/10 * CORS 설정 */ +/** + * @author 엄상은 + * @since 2024/02/26 + * CORS 설정 에러 해결 + */ @Configuration -public class CorsConfig { - @Bean - public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); +public class CorsConfig implements WebMvcConfigurer { + private final long MAX_AGE_SECS = 3600; - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("http://localhost:3000") + .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(MAX_AGE_SECS); } } \ No newline at end of file