2026-09-15 09:07:16 +00:00
|
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
|
|
|
import { homedir } from "node:os";
|
|
|
|
|
import { dirname, join, resolve } from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
import { defineConfig, loadEnv, type ServerOptions } from "vite";
|
2026-09-14 09:08:20 +00:00
|
|
|
import react from "@vitejs/plugin-react";
|
|
|
|
|
|
2026-09-15 09:07:16 +00:00
|
|
|
const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
|
|
|
|
|
|
function localCerts(): { cert: Buffer; key: Buffer } | undefined {
|
|
|
|
|
const home = homedir();
|
|
|
|
|
for (const dir of [join(home, ".lazyboy", "certs"), join(home, ".grokboy", "certs")]) {
|
|
|
|
|
const cert = join(dir, "server.pem");
|
|
|
|
|
const key = join(dir, "server.key");
|
|
|
|
|
if (existsSync(cert) && existsSync(key)) {
|
|
|
|
|
return { cert: readFileSync(cert), key: readFileSync(key) };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
const env = loadEnv(mode, rootDir, "");
|
|
|
|
|
const version = (process.env.LAZYBOY_VERSION || env.LAZYBOY_VERSION || "0.1.0").trim() || "0.1.0";
|
|
|
|
|
const https = localCerts();
|
|
|
|
|
const backend = https ? "https://127.0.0.1:8787" : "http://127.0.0.1:8787";
|
|
|
|
|
const server: ServerOptions = {
|
2026-09-14 09:08:20 +00:00
|
|
|
port: 5173,
|
2026-09-15 09:07:16 +00:00
|
|
|
host: true,
|
2026-09-14 09:08:20 +00:00
|
|
|
proxy: {
|
2026-09-15 09:07:16 +00:00
|
|
|
"/api": { target: backend, secure: false },
|
|
|
|
|
"/novnc": { target: backend, ws: true, secure: false },
|
|
|
|
|
"/lazyboy-ca.crt": { target: backend, secure: false },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
if (https) server.https = https;
|
|
|
|
|
return {
|
|
|
|
|
plugins: [react()],
|
|
|
|
|
define: {
|
|
|
|
|
"import.meta.env.LAZYBOY_VERSION": JSON.stringify(version),
|
2026-09-14 09:08:20 +00:00
|
|
|
},
|
2026-09-15 09:07:16 +00:00
|
|
|
server,
|
|
|
|
|
preview: {
|
|
|
|
|
port: 4173,
|
|
|
|
|
},
|
|
|
|
|
};
|
2026-09-14 09:08:20 +00:00
|
|
|
});
|
2026-09-15 09:07:16 +00:00
|
|
|
|