From f99ea93d00ca19c12ed67a9543c2d185a7c55ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=ED=98=B8=EC=9C=A4?= Date: Fri, 15 Dec 2023 03:14:45 +0900 Subject: [PATCH] =?UTF-8?q?header,=20cookie=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chwipoClova/common/config/CorsConfig.java | 29 +++++++++++++++++++ .../common/config/WebMvcConfig.java | 2 -- .../common/filter/RequestFilter.java | 4 +-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/chwipoClova/common/config/CorsConfig.java 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);