import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' import type { ProxyOptions } from 'vite' export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const apiProxyTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:9999' const apiProxy = (): ProxyOptions => ({ target: apiProxyTarget, changeOrigin: true, configure: (proxy) => { proxy.on('proxyRes', (proxyRes) => { const location = proxyRes.headers.location if (typeof location === 'string' && location.startsWith(apiProxyTarget)) { proxyRes.headers.location = location.replace(apiProxyTarget, '') } }) }, }) return { plugins: [react()], server: { port: 5173, host: '0.0.0.0', proxy: { '/uat': apiProxy(), '/cmm': apiProxy(), '/sym': apiProxy(), '/cop': apiProxy(), '/uss': apiProxy(), '/sec': apiProxy(), '/sts': apiProxy(), '/react': apiProxy(), }, }, } })