Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>/?warpgate-ticket=...`)이 있으면 Warpgate로 프록시한다.
// Authorization은 로그인 토큰이 쓰므로 티켓은 쿼리로 붙인다. VITE_ 접두사가 없어 번들에 포함되지 않는다.
function resolveApiProxy(env: Record<string, string>) {
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()],
Expand All @@ -17,11 +34,11 @@ export default defineConfig(({ mode }) => {
port: 5173,
proxy: {
'/api': {
target: apiBaseUrl,
...apiProxy,
changeOrigin: true,
},
'/admin/api': {
target: apiBaseUrl,
...apiProxy,
changeOrigin: true,
},
},
Expand Down
Loading