diff --git a/public/js/app.js b/public/js/app.js index b1fd073..56c5602 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -21,9 +21,12 @@ function queryParams() { return params.toString(); } +// Detect base path from current URL (works behind nginx proxy) +const BASE_PATH = window.location.pathname.replace(/\/$/, ''); + async function fetchAPI(endpoint) { const sep = endpoint.includes('?') ? '&' : '?'; - const res = await fetch(`/api/${endpoint}${sep}${queryParams()}`, { headers: apiHeaders() }); + const res = await fetch(`${BASE_PATH}/api/${endpoint}${sep}${queryParams()}`, { headers: apiHeaders() }); if (!res.ok) throw new Error(`API error: ${res.status}`); return res.json(); } @@ -314,7 +317,7 @@ lucide.createIcons(); (async function init() { // Check auth first before loading any data - const res = await fetch('/api/summary?period=24h', { headers: apiHeaders() }); + const res = await fetch(`${BASE_PATH}/api/summary?period=24h`, { headers: apiHeaders() }); if (res.status === 401) { const key = prompt('Enter Dashboard API Key:'); if (key) {