From 2ecdd363b1c354c3bfd83bf233a57eeb2597812e Mon Sep 17 00:00:00 2001 From: ByungCheol Date: Sun, 31 May 2026 19:12:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20CORS=EC=97=90=20Capacitor=20=EC=95=B1?= =?UTF-8?q?=20=EC=98=A4=EB=A6=AC=EC=A7=84=20=ED=97=88=EC=9A=A9=20(?= =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=B8=8C=EB=A6=AC=EB=93=9C=20=EC=95=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- .../java/com/sb/web/common/config/CorsConfig.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sb/web/common/config/CorsConfig.java b/src/main/java/com/sb/web/common/config/CorsConfig.java index 9d3fa69..78db081 100644 --- a/src/main/java/com/sb/web/common/config/CorsConfig.java +++ b/src/main/java/com/sb/web/common/config/CorsConfig.java @@ -5,8 +5,11 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** - * Vue 개발 서버(기본 5173)에서의 호출을 허용하기 위한 CORS 설정. - * 운영 환경에서는 allowedOrigins 를 실제 도메인으로 제한하세요. + * CORS 설정. + * - Vue 개발 서버(기본 5173) + * - Capacitor 안드로이드/iOS 앱 WebView 오리진 (capacitor://localhost, http(s)://localhost) + * 운영 웹은 Nginx 가 같은 도메인의 /api 로 프록시하므로 CORS 불필요. + * 별도 도메인에서 호출한다면 그 도메인을 allowedOrigins 에 추가하세요. */ @Configuration public class CorsConfig implements WebMvcConfigurer { @@ -14,7 +17,12 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/api/**") - .allowedOrigins("http://localhost:5173") + .allowedOrigins( + "http://localhost:5173", // Vue 개발 서버 + "capacitor://localhost", // Capacitor (iOS scheme) + "https://localhost", // Capacitor Android (기본 https scheme) + "http://localhost" // Capacitor Android (http scheme) + ) .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") .allowedHeaders("*") .allowCredentials(true)