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 <noreply@anthropic.com>
This commit is contained in:
DJP 2026-03-11 17:08:37 -04:00
parent 4564a23f99
commit 367ea56b34

View file

@ -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) {