feat(web-probe): add multi-sentinel registry
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// SPEC: PJ2026-01060508 Web哨兵 draft-2026-06-26-p9-desktop-view-density.
|
||||
// SPEC: PJ2026-01060508 Web哨兵 draft-2026-06-26-p9-multi-web-probe-sentinel.
|
||||
// Responsibility: Static dashboard shell and asset serving for the web-probe sentinel frontend.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { rootPath } from "./config";
|
||||
@@ -6,6 +7,7 @@ import { rootPath } from "./config";
|
||||
interface DashboardShellConfig {
|
||||
readonly node: string;
|
||||
readonly lane: string;
|
||||
readonly sentinelId: string;
|
||||
readonly plan: { readonly ok: boolean };
|
||||
readonly publicExposure: Record<string, unknown>;
|
||||
}
|
||||
@@ -15,13 +17,14 @@ const DASHBOARD_CONTRACT_VERSION = "draft-2026-06-26-p9-desktop-view-density";
|
||||
|
||||
export function renderWebProbeSentinelDashboardHtml(config: DashboardShellConfig): string {
|
||||
const publicOrigin = stringOrNull(config.publicExposure.publicBaseUrl) ?? "";
|
||||
const basePath = publicBasePath(publicOrigin);
|
||||
return `<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>HWLAB Web哨兵</title>
|
||||
<link rel="stylesheet" href="/dashboard/assets/dashboard.css">
|
||||
<link rel="stylesheet" href="${escapeAttr(basePath)}/dashboard/assets/dashboard.css">
|
||||
</head>
|
||||
<body>
|
||||
<main
|
||||
@@ -29,6 +32,8 @@ export function renderWebProbeSentinelDashboardHtml(config: DashboardShellConfig
|
||||
class="sentinel-shell"
|
||||
data-node="${escapeAttr(config.node)}"
|
||||
data-lane="${escapeAttr(config.lane)}"
|
||||
data-sentinel-id="${escapeAttr(config.sentinelId)}"
|
||||
data-base-path="${escapeAttr(basePath)}"
|
||||
data-public-origin="${escapeAttr(publicOrigin)}"
|
||||
data-config-ready="${config.plan.ok ? "true" : "false"}"
|
||||
data-contract-version="${DASHBOARD_CONTRACT_VERSION}"
|
||||
@@ -213,11 +218,20 @@ export function renderWebProbeSentinelDashboardHtml(config: DashboardShellConfig
|
||||
|
||||
<div id="copy-toast" class="copy-toast" hidden>已复制</div>
|
||||
</main>
|
||||
<script type="module" src="/dashboard/assets/dashboard.js"></script>
|
||||
<script type="module" src="${escapeAttr(basePath)}/dashboard/assets/dashboard.js"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
function publicBasePath(publicBaseUrl: string): string {
|
||||
try {
|
||||
const path = new URL(publicBaseUrl).pathname.replace(/\/+$/u, "");
|
||||
return path === "/" ? "" : path;
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function webProbeSentinelDashboardAssetResponse(pathname: string): Response | null {
|
||||
if (pathname === "/dashboard/assets/dashboard.css") return textAsset(`${DASHBOARD_ASSET_ROOT}/dashboard.css`, "text/css; charset=utf-8");
|
||||
if (pathname === "/dashboard/assets/dashboard.js") return textAsset(`${DASHBOARD_ASSET_ROOT}/dashboard.js`, "application/javascript; charset=utf-8");
|
||||
|
||||
Reference in New Issue
Block a user