/// import http from 'node:http' import https from 'node:https' import { defineConfig, loadEnv, type ProxyOptions } from 'vite' import react from '@vitejs/plugin-react' import tailwindcss from '@tailwindcss/vite' import { apiOrigin } from './src/services/apiBase' function apiProxy(target: string): ProxyOptions { const secure = target.startsWith('https:') // keepAlive would let a second chat reuse the socket that is still streaming. const agent = secure ? new https.Agent({ keepAlive: false }) : new http.Agent({ keepAlive: false }) return { target, changeOrigin: true, timeout: 0, proxyTimeout: 0, agent, configure(proxy) { proxy.on('proxyRes', (proxyRes, _req, res) => { const type = String(proxyRes.headers['content-type'] || '') if (!type.includes('text/event-stream')) return delete proxyRes.headers['content-length'] res.setHeader('Cache-Control', 'no-cache, no-transform') res.setHeader('X-Accel-Buffering', 'no') }) }, } } export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const backendOrigin = apiOrigin(env.API_BASE_URL) || 'http://127.0.0.1:5670' return { plugins: [react(), tailwindcss()], server: { port: 5173, proxy: { '/api': apiProxy(backendOrigin), '/images': { target: backendOrigin, changeOrigin: true }, '/files': { target: backendOrigin, changeOrigin: true }, }, }, test: { environment: 'jsdom', globals: true, setupFiles: './src/test/setup.ts', }, } })