diff --git a/src/main/java/com/chwipoClova/common/config/CorsConfig.java b/src/main/java/com/chwipoClova/common/config/CorsConfig.java new file mode 100644 index 0000000..2043f61 --- /dev/null +++ b/src/main/java/com/chwipoClova/common/config/CorsConfig.java @@ -0,0 +1,29 @@ +package com.chwipoClova.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; + +import java.util.List; + +@Configuration +public class CorsConfig { + + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration config = new CorsConfiguration(); + + config.setAllowCredentials(true); + config.setAllowedOrigins(List.of("http://localhost:3000")); + config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); + config.setAllowedHeaders(List.of("*")); + config.setExposedHeaders(List.of("*")); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + return source; + } + +} diff --git a/src/main/java/com/chwipoClova/common/config/WebMvcConfig.java b/src/main/java/com/chwipoClova/common/config/WebMvcConfig.java index 9f587f3..1a29668 100644 --- a/src/main/java/com/chwipoClova/common/config/WebMvcConfig.java +++ b/src/main/java/com/chwipoClova/common/config/WebMvcConfig.java @@ -5,8 +5,6 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@Configuration -@EnableWebMvc public class WebMvcConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { diff --git a/src/main/java/com/chwipoClova/common/filter/RequestFilter.java b/src/main/java/com/chwipoClova/common/filter/RequestFilter.java index efada37..d9575cb 100644 --- a/src/main/java/com/chwipoClova/common/filter/RequestFilter.java +++ b/src/main/java/com/chwipoClova/common/filter/RequestFilter.java @@ -60,7 +60,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha "[REQUEST] {} - {} {} - {}\n" + "Headers : {}\n" + "Request : {}\n" + - "Headers : {}\n" + + //"Headers : {}\n" + "Response : {}\n", ((HttpServletRequest) customRequestWrapper).getMethod(), ((HttpServletRequest) customRequestWrapper).getRequestURI(), @@ -68,7 +68,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha (end - start) / 1000.0, getHeaders(customRequestWrapper), buildAccessLog(customRequestWrapper), - getHeaders(responseWrapper), + //getHeaders(responseWrapper), getResponseBody(responseWrapper)); } else { log.info("[REQUEST] {} - {} {} - {}", ((HttpServletRequest) customRequestWrapper).getMethod(), ((HttpServletRequest) customRequestWrapper).getRequestURI(), responseWrapper.getStatus(), (end - start) / 1000.0);