From d339fbd91791b94787f1af3999790953533b9f8b Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 16 Jun 2026 10:06:10 +0800 Subject: [PATCH] fix: prefix panel API requests with subpath for nginx proxy Stats and node API calls were hitting /api/* at the site root instead of the hidden PANEL_PATH, causing stats to show unavailable behind nginx. Co-authored-by: Cursor --- panel/static/app.js | 15 +++++++++++---- panel/templates/base.html | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/panel/static/app.js b/panel/static/app.js index afabe2e..436bb2c 100644 --- a/panel/static/app.js +++ b/panel/static/app.js @@ -5,6 +5,11 @@ function toast(msg) { setTimeout(() => el.classList.add("hidden"), 2200); } +function apiUrl(path) { + const base = (document.body.dataset.base || "").replace(/\/$/, ""); + return `${base}${path}`; +} + document.querySelectorAll("[data-copy]").forEach((btn) => { btn.addEventListener("click", async () => { const text = btn.dataset.copy; @@ -40,7 +45,7 @@ if (confirmAddBtn) { const name = nodeName.value.trim() || "新节点"; confirmAddBtn.disabled = true; try { - const res = await fetch("/api/nodes", { + const res = await fetch(apiUrl("/api/nodes"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name }), @@ -62,7 +67,7 @@ document.querySelectorAll(".delete-btn").forEach((btn) => { if (!confirm("确定删除该节点?删除后对应链接将失效。")) return; btn.disabled = true; try { - const res = await fetch(`/api/nodes/${id}`, { method: "DELETE" }); + const res = await fetch(apiUrl(`/api/nodes/${id}`), { method: "DELETE" }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "删除失败"); location.reload(); @@ -123,8 +128,10 @@ function updateStats(data) { async function refreshStats() { try { - const res = await fetch("/api/stats"); - if (!res.ok) return; + const res = await fetch(apiUrl("/api/stats")); + if (!res.ok) { + throw new Error(`HTTP ${res.status}`); + } const data = await res.json(); updateStats(data); } catch { diff --git a/panel/templates/base.html b/panel/templates/base.html index 83221ba..758c8b5 100644 --- a/panel/templates/base.html +++ b/panel/templates/base.html @@ -6,7 +6,7 @@ {% block title %}jiedian 面板{% endblock %} - + {% block body %}{% endblock %} {% block scripts %}{% endblock %}