From 577c2bad1731e6ebd73481ada0510649cd369029 Mon Sep 17 00:00:00 2001 From: hyejj19 Date: Sat, 24 Oct 2026 11:06:32 +0900 Subject: [PATCH] fix: proxy dev API through Warpgate when API_SERVER_WARP_URL is set Co-Authored-By: Claude Opus 5.5 --- vite.config.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 49343e7..33b90a5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,9 +2,26 @@ import path from 'path'; import react from '@vitejs/plugin-react'; import { defineConfig, loadEnv } from 'vite'; +// API_SERVER_WARP_URL(`https:///?warpgate-ticket=...`)이 있으면 Warpgate로 프록시한다. +// Authorization은 로그인 토큰이 쓰므로 티켓은 쿼리로 붙인다. VITE_ 접두사가 없어 번들에 포함되지 않는다. +function resolveApiProxy(env: Record) { + if (env.API_SERVER_WARP_URL) { + const warpUrl = new URL(env.API_SERVER_WARP_URL); + const ticket = warpUrl.searchParams.get('warpgate-ticket'); + return { + target: warpUrl.origin, + rewrite: ticket + ? (requestPath: string) => + `${requestPath}${requestPath.includes('?') ? '&' : '?'}warpgate-ticket=${encodeURIComponent(ticket)}` + : undefined, + }; + } + return { target: env.VITE_API_BASE_URL || 'http://localhost:8080', rewrite: undefined }; +} + export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); - const apiBaseUrl = env.VITE_API_BASE_URL || 'http://localhost:8080'; + const apiProxy = resolveApiProxy(env); return { plugins: [react()], @@ -17,11 +34,11 @@ export default defineConfig(({ mode }) => { port: 5173, proxy: { '/api': { - target: apiBaseUrl, + ...apiProxy, changeOrigin: true, }, '/admin/api': { - target: apiBaseUrl, + ...apiProxy, changeOrigin: true, }, },