diff --git a/vite.operator-dashboard.config.mjs b/vite.operator-dashboard.config.mjs new file mode 100644 index 0000000..1561f3e --- /dev/null +++ b/vite.operator-dashboard.config.mjs @@ -0,0 +1,41 @@ +import react from '@vitejs/plugin-react'; +import { defineConfig } from 'vite'; + +function buildProxyConfig({ target, authHeader, websocket = false }) { + return { + target, + changeOrigin: true, + ws: websocket, + configure(proxy) { + if (!authHeader) return; + proxy.on('proxyReq', (proxyReq) => { + proxyReq.setHeader('Authorization', authHeader); + }); + proxy.on('proxyReqWs', (proxyReq) => { + proxyReq.setHeader('Authorization', authHeader); + }); + }, + }; +} + +const target = process.env.OPERATOR_DASHBOARD_DEV_UPSTREAM_URL || 'http://127.0.0.1:18090'; +const authHeader = process.env.OPERATOR_DASHBOARD_DEV_BASIC_AUTH_HEADER || ''; + +export default defineConfig({ + plugins: [react()], + root: 'src/operator-dashboard/static', + build: { + outDir: '../dist', + emptyOutDir: true, + }, + server: { + host: process.env.OPERATOR_DASHBOARD_DEV_HOST || '127.0.0.1', + port: Number(process.env.OPERATOR_DASHBOARD_DEV_PORT || 5173), + strictPort: true, + proxy: { + '/api': buildProxyConfig({ target, authHeader }), + '/healthz': buildProxyConfig({ target, authHeader }), + '/ws': buildProxyConfig({ target, authHeader, websocket: true }), + }, + }, +});