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:
+11
-4
@@ -5,6 +5,11 @@ function toast(msg) {
|
|||||||
setTimeout(() => el.classList.add("hidden"), 2200);
|
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) => {
|
document.querySelectorAll("[data-copy]").forEach((btn) => {
|
||||||
btn.addEventListener("click", async () => {
|
btn.addEventListener("click", async () => {
|
||||||
const text = btn.dataset.copy;
|
const text = btn.dataset.copy;
|
||||||
@@ -40,7 +45,7 @@ if (confirmAddBtn) {
|
|||||||
const name = nodeName.value.trim() || "新节点";
|
const name = nodeName.value.trim() || "新节点";
|
||||||
confirmAddBtn.disabled = true;
|
confirmAddBtn.disabled = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/nodes", {
|
const res = await fetch(apiUrl("/api/nodes"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name }),
|
body: JSON.stringify({ name }),
|
||||||
@@ -62,7 +67,7 @@ document.querySelectorAll(".delete-btn").forEach((btn) => {
|
|||||||
if (!confirm("确定删除该节点?删除后对应链接将失效。")) return;
|
if (!confirm("确定删除该节点?删除后对应链接将失效。")) return;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
try {
|
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();
|
const data = await res.json();
|
||||||
if (!res.ok) throw new Error(data.error || "删除失败");
|
if (!res.ok) throw new Error(data.error || "删除失败");
|
||||||
location.reload();
|
location.reload();
|
||||||
@@ -123,8 +128,10 @@ function updateStats(data) {
|
|||||||
|
|
||||||
async function refreshStats() {
|
async function refreshStats() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/stats");
|
const res = await fetch(apiUrl("/api/stats"));
|
||||||
if (!res.ok) return;
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status}`);
|
||||||
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
updateStats(data);
|
updateStats(data);
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<title>{% block title %}jiedian 面板{% endblock %}</title>
|
<title>{% block title %}jiedian 面板{% endblock %}</title>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body{% if request.script_root %} data-base="{{ request.script_root }}"{% endif %}>
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
{% block scripts %}{% endblock %}
|
{% block scripts %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user