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:
+18
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user