import path from 'node:path'; import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; import tailwindcss from '@tailwindcss/vite'; import { tanstackRouter } from '@tanstack/router-plugin/vite'; // https://vite.dev/config/ export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), 'VITE_'); const directusUrl = env.VITE_DEV_DIRECTUS_URL ?? 'http://localhost:8055'; const processorWsUrl = env.VITE_DEV_PROCESSOR_WS_URL ?? 'ws://localhost:8081'; // The WS proxy target needs the ws:// scheme; derive from the http(s) URL. const directusWsUrl = directusUrl.replace(/^http(s?):\/\//, 'ws$1://'); return { plugins: [ // Router plugin must run BEFORE @vitejs/plugin-react so the generated // routeTree is in place when React's transform runs. tanstackRouter({ target: 'react', autoCodeSplitting: true }), react(), tailwindcss(), ], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, server: { port: 5173, proxy: { // Directus REST + GraphQL. Strip /api prefix; SPA hits relative URLs. '/api': { target: directusUrl, changeOrigin: true, rewrite: (p) => p.replace(/^\/api/, ''), }, // Directus business-plane WebSocket. Strip /ws-business; rewrite to // Directus's actual /websocket path. '/ws-business': { target: directusWsUrl, ws: true, changeOrigin: true, rewrite: (p) => p.replace(/^\/ws-business/, '/websocket'), }, // Processor live-position WebSocket. Strip /ws-live; Processor binds // bare (no path prefix) per the Phase 1.5 task spec. '/ws-live': { target: processorWsUrl, ws: true, changeOrigin: true, rewrite: (p) => p.replace(/^\/ws-live/, ''), }, }, }, }; });