From 1f39ad16937e60c470aa4327623674c4595c08fa Mon Sep 17 00:00:00 2001 From: iseunghag Date: Mon, 22 Jan 2024 13:19:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#232=20infra:cors=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shallwe/global/config/WebConfig.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/shallwe/global/config/WebConfig.java diff --git a/src/main/java/com/shallwe/global/config/WebConfig.java b/src/main/java/com/shallwe/global/config/WebConfig.java new file mode 100644 index 00000000..313df4b3 --- /dev/null +++ b/src/main/java/com/shallwe/global/config/WebConfig.java @@ -0,0 +1,23 @@ +package com.shallwe.global.config; + +import lombok.RequiredArgsConstructor; +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; + +@RequiredArgsConstructor +@Configuration +public class WebConfig implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") // url 패턴 + .allowedOriginPatterns("*") + // todo: server url 생성 시 변경 필요 +// .allowedOrigins("url:8080", "http://localhost:8080") + .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PATCH.name(), HttpMethod.DELETE.name(), HttpMethod.OPTIONS.name(), + HttpMethod.HEAD.name(), HttpMethod.TRACE.name(), HttpMethod.OPTIONS.name()) // 허용 method + .allowedHeaders("Authorization", "Content-Type"); // 허용 header + .allowCredentials(true); + } +} From 0d3636cb985681a6e4c2ffd89378cd867658cbaa Mon Sep 17 00:00:00 2001 From: iseunghag Date: Mon, 22 Jan 2024 13:21:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?cors=EC=84=A4=EC=A0=95=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/shallwe/global/config/WebConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/shallwe/global/config/WebConfig.java b/src/main/java/com/shallwe/global/config/WebConfig.java index 313df4b3..5b72f0f6 100644 --- a/src/main/java/com/shallwe/global/config/WebConfig.java +++ b/src/main/java/com/shallwe/global/config/WebConfig.java @@ -18,6 +18,5 @@ public void addCorsMappings(CorsRegistry registry) { .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PATCH.name(), HttpMethod.DELETE.name(), HttpMethod.OPTIONS.name(), HttpMethod.HEAD.name(), HttpMethod.TRACE.name(), HttpMethod.OPTIONS.name()) // 허용 method .allowedHeaders("Authorization", "Content-Type"); // 허용 header - .allowCredentials(true); } }