Running `pnpm dev` alone gave ECONNREFUSED on every request, because nothing was listening on :7788. Two separate causes: - the backend simply was not running, and - Vite bound [::1]:5173 while the proxy target was "localhost", which Node resolves to ::1 first. The Go server binds IPv4, so even with the backend up the proxy could fail before falling back. - vite.config.ts: proxy target is now 127.0.0.1 explicitly and overridable via VELLUM_API; server.host is true so both stacks are served. - scripts/dev.sh + `make dev`: builds the backend, waits for /healthz, starts Vite, and stops the backend on exit. Ctrl-C tears down both. - README documents that running Vite alone needs the backend already up.
28 lines
830 B
TypeScript
28 lines
830 B
TypeScript
import { defineConfig } from 'vite'
|
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
|
|
// The backend the dev server proxies to. 127.0.0.1 rather than localhost on
|
|
// purpose: Node resolves "localhost" to ::1 first, and the Go server binds
|
|
// IPv4, so the proxy would fail before falling back.
|
|
const apiTarget = process.env.VELLUM_API ?? 'http://127.0.0.1:7788'
|
|
|
|
// The bundle is embedded into the Go binary and served from /, so all asset
|
|
// paths must be relative (base: './').
|
|
export default defineConfig({
|
|
plugins: [svelte()],
|
|
base: './',
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: true,
|
|
target: 'es2020',
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
// Listen on both stacks so a browser using either localhost works.
|
|
host: true,
|
|
proxy: {
|
|
'/api': apiTarget,
|
|
'/healthz': apiTarget,
|
|
},
|
|
},
|
|
})
|