fix(control-ui): serve dashboard at root

This commit is contained in:
Peter Steinberger
2025-12-19 05:11:08 +00:00
parent 00fc731d64
commit c498348a34
7 changed files with 14 additions and 15 deletions

View File

@@ -248,7 +248,7 @@ struct MenuContent: View {
default:
components.scheme = "http"
}
components.path = "/ui/"
components.path = "/"
components.query = nil
guard let url = components.url else {
throw NSError(domain: "Dashboard", code: 2, userInfo: [

View File

@@ -8,7 +8,8 @@ read_when:
The Control UI is a small **Vite + Lit** single-page app served by the Gateway under:
- `http://<host>:18789/ui/`
- `http://<host>:18789/` (preferred)
- `http://<host>:18789/ui/` (legacy alias)
It speaks **directly to the Gateway WebSocket** on the same port.
@@ -48,4 +49,3 @@ pnpm ui:dev
```
Then point the UI at your Gateway WS URL (e.g. `ws://127.0.0.1:18789`).

View File

@@ -102,7 +102,7 @@ export type CanvasHostConfig = {
};
export type GatewayControlUiConfig = {
/** If false, the Gateway will not serve the Control UI under /ui/. Default: true. */
/** If false, the Gateway will not serve the Control UI (/, /ui/). Default: true. */
enabled?: boolean;
};

View File

@@ -4,6 +4,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
const UI_PREFIX = "/ui/";
const ROOT_PREFIX = "/";
function resolveControlUiRoot(): string | null {
const here = path.dirname(fileURLToPath(import.meta.url));
@@ -88,13 +89,11 @@ export function handleControlUiHttpRequest(
if (url.pathname === "/ui") {
res.statusCode = 302;
res.setHeader("Location", UI_PREFIX);
res.setHeader("Location", "/");
res.end();
return true;
}
if (!url.pathname.startsWith(UI_PREFIX)) return false;
const root = resolveControlUiRoot();
if (!root) {
res.statusCode = 503;
@@ -105,7 +104,12 @@ export function handleControlUiHttpRequest(
return true;
}
const rel = url.pathname.slice(UI_PREFIX.length);
const rel = (() => {
if (url.pathname === ROOT_PREFIX) return "";
if (url.pathname.startsWith(UI_PREFIX)) return url.pathname.slice(UI_PREFIX.length);
if (url.pathname.startsWith("/assets/")) return url.pathname.slice(1);
return url.pathname.slice(1);
})();
const requested = rel && !rel.endsWith("/") ? rel : `${rel}index.html`;
const fileRel = requested || "index.html";
if (!isSafeRelativePath(fileRel)) {

View File

@@ -848,12 +848,6 @@ export async function startGatewayServer(
if (String(req.headers.upgrade ?? "").toLowerCase() === "websocket") return;
if (controlUiEnabled) {
if (req.url === "/") {
res.statusCode = 302;
res.setHeader("Location", "/ui/");
res.end();
return;
}
if (handleControlUiHttpRequest(req, res)) return;
}

View File

@@ -5,6 +5,7 @@
"moduleResolution": "Bundler",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"strict": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"types": ["vite/client"],
"useDefineForClassFields": false

View File

@@ -5,7 +5,7 @@ import { defineConfig } from "vite";
const here = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig({
base: "/ui/",
base: "/",
build: {
outDir: path.resolve(here, "../dist/control-ui"),
emptyOutDir: true,