remove: CORS 설정 제거 및 프론트엔드 API 엔드포인트 수정

This commit is contained in:
이상진 2025-08-04 14:55:23 +09:00
parent b2ff133273
commit 7a79ad68d6
6 changed files with 17 additions and 27 deletions

View File

@ -1 +1 @@
VITE_API_BASE_URL = "http://localhost:8080" VITE_API_BASE_URL = '/api'

View File

@ -1,7 +1,7 @@
import axios, { type AxiosError, type AxiosRequestConfig, type Method } from 'axios'; import axios, { type AxiosError, type AxiosRequestConfig, type Method } from 'axios';
const apiClient = axios.create({ 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, timeout: 10000,
}); });

View File

@ -8,4 +8,19 @@ export default defineConfig({
react(), react(),
tsconfigPaths(), 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/, ''),
},
},
},
}) })

View File

@ -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
}
}

View File

@ -37,5 +37,3 @@ management:
tracing: tracing:
transport: ${OTLP_TRACING_PROTOCOL} transport: ${OTLP_TRACING_PROTOCOL}
endpoint: ${OTLP_TRACING_ENDPOINT} endpoint: ${OTLP_TRACING_ENDPOINT}
cors-origin: ${CORS_ORIGIN}

View File

@ -45,5 +45,3 @@ management:
tracing: tracing:
sampling: sampling:
probability: 1 probability: 1
cors-origin: "http://localhost:5173"