From 76ba81ab0c046cbaa8bc2157af95ef15770ea57c Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 24 Jul 2024 10:53:27 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/config/WebConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 server/src/main/java/server/haengdong/config/WebConfig.java diff --git a/server/src/main/java/server/haengdong/config/WebConfig.java b/server/src/main/java/server/haengdong/config/WebConfig.java new file mode 100644 index 000000000..1a2e484e4 --- /dev/null +++ b/server/src/main/java/server/haengdong/config/WebConfig.java @@ -0,0 +1,20 @@ +package server.haengdong.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + private static final long MAX_AGE_SECS = 3600; + + @Override + public void addCorsMappings(final CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("http://localhost:3000", "https://haengdong.pro", "https://dev.haengdong.pro") + .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE") + .allowedHeaders("*") + .maxAge(MAX_AGE_SECS); + } +} From f98c97a2c6a99e8c59042d157c7d6e8647913aba Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 24 Jul 2024 11:20:25 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20CORS=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/server/haengdong/config/WebConfig.java | 15 +++++++++++---- server/src/main/resources/application.yml | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/server/haengdong/config/WebConfig.java b/server/src/main/java/server/haengdong/config/WebConfig.java index 1a2e484e4..565985d27 100644 --- a/server/src/main/java/server/haengdong/config/WebConfig.java +++ b/server/src/main/java/server/haengdong/config/WebConfig.java @@ -1,20 +1,27 @@ package server.haengdong.config; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +@RequiredArgsConstructor @Configuration public class WebConfig implements WebMvcConfigurer { - private static final long MAX_AGE_SECS = 3600; + @Value("${cors.max-age}") + private Long maxAge; + + @Value("${cors.allowed-origins}") + private String[] allowedOrigins; @Override - public void addCorsMappings(final CorsRegistry registry) { + public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://localhost:3000", "https://haengdong.pro", "https://dev.haengdong.pro") + .allowedOrigins(allowedOrigins) .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE") .allowedHeaders("*") - .maxAge(MAX_AGE_SECS); + .maxAge(maxAge); } } diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index aca841de8..04a380570 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -14,6 +14,10 @@ spring: format_sql: true show-sql: true +cors: + max-age: 3600 + allowed-origins: http://localhost:3000, https://haengdong.pro, https://dev.haengdong.pro + --- spring: From 99de016a1b5da0194e66bed6a5e15232b9df9b4a Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 24 Jul 2024 11:28:03 +0900 Subject: [PATCH 3/5] =?UTF-8?q?test:=20yml=EC=97=90=20CORS=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/test/resources/application.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/test/resources/application.yml b/server/src/test/resources/application.yml index 49c481eaa..2d02b2712 100644 --- a/server/src/test/resources/application.yml +++ b/server/src/test/resources/application.yml @@ -13,3 +13,6 @@ spring: format_sql: true hibernate: ddl-auto: create-drop +cors: + max-age: 3600 + allowed-origins: http://localhost:8080 From 6800541cb307a21d095b611ef50062e0e08191e9 Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 24 Jul 2024 11:31:25 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20Origin=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 04a380570..e1bdd7f79 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -16,7 +16,7 @@ spring: cors: max-age: 3600 - allowed-origins: http://localhost:3000, https://haengdong.pro, https://dev.haengdong.pro + allowed-origins: http://localhost:3000, https://haengdong.pro, https://dev.haengdong.pro, https://app.haengdong.pro --- From bad8d311ca61755abc3b61b1aa309ab8fd329b93 Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 24 Jul 2024 12:56:02 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20Cors=20=EC=84=A4=EC=A0=95=EC=97=90?= =?UTF-8?q?=20HTTP=20OPTIONS=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/java/server/haengdong/config/WebConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/server/haengdong/config/WebConfig.java b/server/src/main/java/server/haengdong/config/WebConfig.java index 565985d27..129d8b790 100644 --- a/server/src/main/java/server/haengdong/config/WebConfig.java +++ b/server/src/main/java/server/haengdong/config/WebConfig.java @@ -20,7 +20,7 @@ public class WebConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins(allowedOrigins) - .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE") + .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") .allowedHeaders("*") .maxAge(maxAge); }