import { sveltekit } from "@sveltejs/kit/vite"; import { defineConfig } from "vite"; import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; const pkg = JSON.parse( readFileSync( fileURLToPath(new URL("./package.json", import.meta.url)), "utf8", ), ) as { version: string }; // Default upstream gateway addresses used by the dev proxy. Override // by pointing `VITE_DEV_PROXY_TARGET` (REST surface) and // `VITE_DEV_GRPC_PROXY_TARGET` (Connect-Web surface) at a different // gateway when working with a remote stack instead of // `tools/local-dev/`. In production the two surfaces sit behind a // single host; the split here exists only because local-dev runs the // REST listener on :8080 and the authenticated Connect-Web listener // on :9090. const DEV_PROXY_TARGET = process.env.VITE_DEV_PROXY_TARGET ?? "http://localhost:8080"; const DEV_GRPC_PROXY_TARGET = process.env.VITE_DEV_GRPC_PROXY_TARGET ?? "http://localhost:9090"; export default defineConfig({ plugins: [sveltekit()], define: { __APP_VERSION__: JSON.stringify(pkg.version), }, server: { // Same-origin proxy so the browser sees only `localhost:5173` // and never trips a cross-origin preflight against the // gateway's REST + Connect-Web surfaces. Production deployments // serve the UI and the gateway behind a single host, so the // proxy is purely a dev-time convenience. proxy: { "/api": { target: DEV_PROXY_TARGET, changeOrigin: false, }, "/galaxy.gateway.v1.EdgeGateway": { target: DEV_GRPC_PROXY_TARGET, changeOrigin: false, // Connect-Web server-streaming (`SubscribeEvents`) uses // chunked HTTP responses; http-proxy passes them through // transparently as long as buffering stays off, which is // the default. }, }, }, });