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.
39 lines
1 KiB
TypeScript
39 lines
1 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
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(),
|
|
legacy({
|
|
targets: ['ios >= 12', 'safari >= 12'],
|
|
modernPolyfills: true,
|
|
renderLegacyChunks: true,
|
|
}),
|
|
],
|
|
build: {
|
|
target: 'es2017',
|
|
rollupOptions: {
|
|
input: {
|
|
main: resolve(__dirname, 'index.html'),
|
|
admin: resolve(__dirname, 'admin.html'),
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
'/api': serverTarget,
|
|
'/admin': serverTarget,
|
|
'/healthz': serverTarget,
|
|
},
|
|
},
|
|
});
|