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