feat(ui): proxy dev API and WebSocket requests to a configurable CC

This commit is contained in:
lda committed 2026-10-21 00:48:12 +07:00 Verified
1 parent 03c1f14dba
commit b1a515e1aa
4 files changed
+167 -17

No files matched your search

+48 -17
View File
@@ -1,4 +1,4 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import path from "node:path";
import { fileURLToPath } from "node:url";
@@ -21,22 +21,53 @@ const ReactCompilerConfig = {
runtimeModule: "react-compiler-runtime", // Redirects the missing specifier
};
export default defineConfig({
plugins: [
react({
babel: {
plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
export default defineConfig(({ command, mode, isPreview }) => {
const env = loadEnv(mode, __dirname, "WAKEY_DEV_");
const target = env.WAKEY_DEV_API_TARGET || "http://127.0.0.1:8080";
const dev = command === "serve" && !isPreview;
if (dev) {
const url = new URL(target);
if (
!["http:", "https:"].includes(url.protocol) ||
url.username ||
url.password ||
url.pathname !== "/" ||
url.search ||
url.hash
) {
throw new Error(
"WAKEY_DEV_API_TARGET must be an HTTP(S) origin without credentials or a path",
);
}
}
return {
plugins: [
react({
babel: {
plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
},
}),
tailwindcss(),
],
base: "/ui/",
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
}),
tailwindcss(),
],
base: "/ui/",
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
build: {
sourcemap: debugEnabled(),
},
build: {
sourcemap: debugEnabled(),
},
// Keep browser requests same-origin, including terminal/event WebSockets.
// WAKEY_DEV_* is read only by this config, never exposed as VITE_* client data.
server: dev
? {
host: "127.0.0.1",
proxy: {
"^/api/": { target, changeOrigin: true, ws: true },
"^/healthz$": { target, changeOrigin: true },
},
}
: undefined,
};
});