fix(control-ui): serve dashboard at root
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user