From ab668cb31f0f66f66e78c46d813de0f8d30790dd Mon Sep 17 00:00:00 2001 From: Patrik Korytar Date: Tue, 28 Jul 2026 16:56:49 +0200 Subject: [PATCH] NCL-9487 Support custom local dev host --- .gitignore | 5 ++++- vite.config.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 73f73077..38407171 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -.devcontainer/ \ No newline at end of file +.devcontainer/ + +# local dev TLS certs (mkcert) +certs/ diff --git a/vite.config.ts b/vite.config.ts index 41506b45..14e21e96 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,13 +1,32 @@ import react from '@vitejs/plugin-react'; +import fs from 'node:fs'; import { defineConfig } from 'vite'; import tsconfigPaths from 'vite-tsconfig-paths'; +/** + * Local dev hostname, mapped to 127.0.0.1 in /etc/hosts + * + * Required to make devel REST API and localhost UI same origin. + */ +const DEV_HOST = process.env.VITE_DEV_HOST; + +/** + * Optional locally-trusted TLS cert (git-ignored): + * mkcert -install + * mkcert -key-file certs/dev-key.pem -cert-file certs/dev-cert.pem + */ +const https = fs.existsSync('certs/dev-cert.pem') + ? { key: fs.readFileSync('certs/dev-key.pem'), cert: fs.readFileSync('certs/dev-cert.pem') } + : undefined; + // https://vitejs.dev/config/ export default () => { return defineConfig({ plugins: [react(), tsconfigPaths()], server: { port: 3000, + https, + ...(DEV_HOST && { host: DEV_HOST, allowedHosts: [DEV_HOST] }), }, }); };