feat: expose boss via nginx base path

This commit is contained in:
Codex
2026-03-23 13:31:23 +08:00
parent bc04c439fb
commit 5c3636fe6a
9 changed files with 149 additions and 44 deletions

View File

@@ -10,6 +10,24 @@ const state = {
banner: null,
};
function normalizeBasePath(pathname) {
if (!pathname || pathname === "/") {
return "";
}
return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
}
const appBasePath = normalizeBasePath(new URL(".", import.meta.url).pathname);
function resolveUrl(path) {
if (/^https?:\/\//.test(path)) {
return path;
}
return `${appBasePath}${path}`;
}
const TASK_GROUPS = [
{ title: "进行中", statuses: ["assigned", "running"] },
{ title: "等待处理", statuses: ["planning", "queued"] },
@@ -90,7 +108,7 @@ function renderBanner() {
}
async function request(url, options = {}) {
const response = await fetch(url, {
const response = await fetch(resolveUrl(url), {
headers: { "Content-Type": "application/json" },
...options,
});
@@ -791,7 +809,7 @@ elements.resetDemo.addEventListener("click", async () => {
render();
});
const stream = new EventSource("/api/events/stream");
const stream = new EventSource(resolveUrl("/api/events/stream"));
stream.onopen = () => {
const wasReconnecting = state.connection === "reconnecting";

View File

@@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Boss Control Plane</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="stylesheet" href="/styles.css" />
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<div class="shell">
@@ -107,6 +107,6 @@
</main>
</div>
<script type="module" src="/app.js"></script>
<script type="module" src="./app.js"></script>
</body>
</html>