From 367ea56b345767d0db1372fb03fe2ec3ae29be06 Mon Sep 17 00:00:00 2001 From: DJP Date: Wed, 11 Mar 2026 17:08:37 -0400 Subject: [PATCH] fix: Use relative base path for API calls behind nginx proxy When served at /librechat-analytics/, API calls now correctly target /librechat-analytics/api/ instead of /api/. Co-Authored-By: Claude Opus 4.6 --- public/js/app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) {