From 7a79ad68d6e865a86c9503f210ba501b569726fa Mon Sep 17 00:00:00 2001 From: pricelees Date: Mon, 4 Aug 2025 14:55:23 +0900 Subject: [PATCH] =?UTF-8?q?remove:=20CORS=20=EC=84=A4=EC=A0=95=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20=ED=94=84=EB=A1=A0=ED=8A=B8=EC=97=94?= =?UTF-8?q?=EB=93=9C=20API=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8?= =?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 --- frontend/.env | 2 +- frontend/src/api/apiClient.ts | 2 +- frontend/vite.config.ts | 15 +++++++++++++ .../roomescape/common/config/CorsConfig.kt | 21 ------------------- src/main/resources/application-deploy.yaml | 2 -- src/main/resources/application-local.yaml | 2 -- 6 files changed, 17 insertions(+), 27 deletions(-) delete mode 100644 src/main/kotlin/roomescape/common/config/CorsConfig.kt diff --git a/frontend/.env b/frontend/.env index 2717bd56..2131aae2 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1 @@ -VITE_API_BASE_URL = "http://localhost:8080" \ No newline at end of file +VITE_API_BASE_URL = '/api' \ No newline at end of file diff --git a/frontend/src/api/apiClient.ts b/frontend/src/api/apiClient.ts index 83090c44..6e488ac3 100644 --- a/frontend/src/api/apiClient.ts +++ b/frontend/src/api/apiClient.ts @@ -1,7 +1,7 @@ import axios, { type AxiosError, type AxiosRequestConfig, type Method } from 'axios'; const apiClient = axios.create({ - baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080', + baseURL: import.meta.env.VITE_API_BASE_URL || '/api', timeout: 10000, }); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 1c97543f..9fe3fabb 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -8,4 +8,19 @@ export default defineConfig({ react(), tsconfigPaths(), ], + server: { + proxy: { + '/api': { + // 실제 백엔드 서버 주소로 전달 + target: 'http://localhost:8080', + + // Origin 헤더를 target의 Origin으로 변경 (CORS 에러 방지) + changeOrigin: true, + + // Ingress의 rewrite-target과 동일한 역할. + // '/api/themes' -> '/themes'로 경로를 재작성하여 백엔드에 전달 + rewrite: (path) => path.replace(/^\/api/, ''), + }, + }, + }, }) diff --git a/src/main/kotlin/roomescape/common/config/CorsConfig.kt b/src/main/kotlin/roomescape/common/config/CorsConfig.kt deleted file mode 100644 index dfc8c9cd..00000000 --- a/src/main/kotlin/roomescape/common/config/CorsConfig.kt +++ /dev/null @@ -1,21 +0,0 @@ -package roomescape.common.config - -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 - -@Configuration -class CorsConfig : WebMvcConfigurer { - - @Value("\${cors-origin}") - private lateinit var origin: String - - override fun addCorsMappings(registry: CorsRegistry) { - registry.addMapping("/**") - .allowedOrigins(origin) - .allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") - .allowedHeaders("Authorization", "Content-Type") - .maxAge(3600) // 1 hour - } -} diff --git a/src/main/resources/application-deploy.yaml b/src/main/resources/application-deploy.yaml index 27e92be5..6fc8619b 100644 --- a/src/main/resources/application-deploy.yaml +++ b/src/main/resources/application-deploy.yaml @@ -37,5 +37,3 @@ management: tracing: transport: ${OTLP_TRACING_PROTOCOL} endpoint: ${OTLP_TRACING_ENDPOINT} - -cors-origin: ${CORS_ORIGIN} \ No newline at end of file diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index 37f62b36..3ed9a706 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -45,5 +45,3 @@ management: tracing: sampling: probability: 1 - -cors-origin: "http://localhost:5173" \ No newline at end of file