From 5ef692767401bf91284cd33772e47de65f97a414 Mon Sep 17 00:00:00 2001 From: gitchan Date: Thu, 29 Feb 2024 12:22:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20CORS=20=EC=84=A4=EC=A0=95=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sunflower/server/config/WebConfig.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/sunflower/server/config/WebConfig.java b/server/src/main/java/sunflower/server/config/WebConfig.java index 1707a3c..7f7ac81 100644 --- a/server/src/main/java/sunflower/server/config/WebConfig.java +++ b/server/src/main/java/sunflower/server/config/WebConfig.java @@ -1,20 +1,30 @@ package sunflower.server.config; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import static org.springframework.http.HttpHeaders.LOCATION; - @Configuration public class WebConfig implements WebMvcConfigurer { - public static final String HTTP_METHODS = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH"; + private static final String[] ALLOWED_ORIGINS = {"**"}; @Override public void addCorsMappings(final CorsRegistry registry) { - registry.addMapping("*") - .allowedMethods(HTTP_METHODS.split(",")) - .exposedHeaders(LOCATION); + registry.addMapping("/**") + .allowedOrigins(ALLOWED_ORIGINS) + .allowedOrigins("http://localhost:80") + .allowedMethods( + HttpMethod.GET.name(), + HttpMethod.POST.name(), + HttpMethod.PUT.name(), + HttpMethod.PATCH.name(), + HttpMethod.DELETE.name(), + HttpMethod.OPTIONS.name() + ) + .allowedHeaders("*") + .exposedHeaders("Location") + .allowCredentials(true); } }