fix: resolve stuck detecting state for panel stats on subpath deploy

Always inject panel_base from PANEL_PATH for static/API URLs and set
SCRIPT_NAME in middleware so /api/stats works behind nginx subpaths.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 10:31:58 +08:00
parent ba361eb5b8
commit d75193d527
5 changed files with 58 additions and 13 deletions
+18 -4
View File
@@ -5,9 +5,18 @@ function toast(msg) {
setTimeout(() => el.classList.add("hidden"), 2200);
}
function panelBase() {
const fromBody = (document.body.dataset.base || "").replace(/\/$/, "");
if (fromBody) return fromBody;
const parts = location.pathname.split("/").filter(Boolean);
if (parts.length && parts[0].startsWith("jiedian-")) {
return `/${parts[0]}`;
}
return "";
}
function apiUrl(path) {
const base = (document.body.dataset.base || "").replace(/\/$/, "");
return `${base}${path}`;
return `${panelBase()}${path}`;
}
function copyText(text) {
@@ -169,18 +178,23 @@ function updateStats(data) {
async function refreshStats() {
try {
const res = await fetch(apiUrl("/api/stats"));
const res = await fetch(apiUrl("/api/stats"), { credentials: "same-origin" });
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
const data = await res.json();
updateStats(data);
} catch {
} catch (err) {
const statusEl = document.getElementById("summaryStatus");
if (statusEl) {
statusEl.textContent = "不可用";
statusEl.className = "status-text err";
}
document.querySelectorAll('[data-role="status"]').forEach((el) => {
el.textContent = "未知";
el.classList.add("offline");
});
console.error("stats refresh failed:", err);
}
}