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 <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 10:06:10 +08:00
parent 6edba863b5
commit d339fbd917
2 changed files with 12 additions and 5 deletions
+11 -4
View File
@@ -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 {
+1 -1
View File
@@ -6,7 +6,7 @@
<title>{% block title %}jiedian 面板{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<body{% if request.script_root %} data-base="{{ request.script_root }}"{% endif %}>
{% block body %}{% endblock %}
{% block scripts %}{% endblock %}
</body>