import { defineConfig, loadEnv } from "vite"; // Where the dev proxy forwards `/api/*` (and the events WS) to. Default to a // local daemon on 127.0.0.1:7070. Override with: // MAESTRO_DAEMON_URL=http://laptop.lan:7070 // `ws://`/`wss://` forms are normalised to http/https, since the proxy needs an // HTTP base URL. function resolveProxyTarget(raw: string | undefined): string { if (!raw) return "http://127.0.0.1:7070"; return raw .replace(/^wss:\/\//, "https://") .replace(/^ws:\/\//, "http://") .replace(/\/+$/, ""); } export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ""); const target = resolveProxyTarget(env.MAESTRO_DAEMON_URL); const secure = target.startsWith("https://"); return { build: { target: "es2022", outDir: "dist", emptyOutDir: true, sourcemap: false, }, server: { port: 5173, proxy: { "/api": { target, changeOrigin: secure, ws: true, secure: false, }, }, }, }; });