dev: make the client's dev-server proxy target configurable via WUTZ_SERVER_PORT

vite.config.ts hardcoded the /api, /admin, /healthz proxy targets to
http://localhost:3000 — the server's default port — so there was no
way to run dev:client against a dev:server started on a different
port (PORT=<n> pnpm dev:server) without editing the config file.

Read the port from WUTZ_SERVER_PORT (same default of 3000 as the
server's own PORT env var) and build the proxy target once.
This commit is contained in:
iris 2026-07-29 20:06:38 +02:00
commit a5698c62bc

View file

@ -3,6 +3,13 @@ import preact from '@preact/preset-vite';
import legacy from '@vitejs/plugin-legacy';
import { resolve } from 'node:path';
// The dev-server proxy target — same default (3000) as the server's own
// `process.env.PORT ?? 3000` in server/src/index.ts. Override with
// `WUTZ_SERVER_PORT` when running `dev:server` on a non-default port, e.g.:
// PORT=4000 pnpm dev:server
// WUTZ_SERVER_PORT=4000 pnpm dev:client
const serverTarget = `http://localhost:${process.env.WUTZ_SERVER_PORT ?? 3000}`;
export default defineConfig({
plugins: [
preact(),
@ -24,9 +31,9 @@ export default defineConfig({
server: {
port: 5173,
proxy: {
'/api': 'http://localhost:3000',
'/admin': 'http://localhost:3000',
'/healthz': 'http://localhost:3000',
'/api': serverTarget,
'/admin': serverTarget,
'/healthz': serverTarget,
},
},
});