Skip to content

Commit a44eea3

Browse files
committed
fix(frontend): detect basePath from URL for config fetch
When running with basePath=/llm-admin, the fetch('/api/config') call doesn't automatically prepend the basePath. Added detectBasePath() function that checks window.location.pathname to determine the correct API endpoint path.
1 parent e2f5d6c commit a44eea3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

frontend/lib/config.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ export interface ConfigContextValue extends RuntimeConfig {
1717

1818
let cachedConfig: RuntimeConfig | null = null;
1919

20+
/**
21+
* Detects the basePath from the current URL.
22+
* In production, the app runs at /llm-admin, so we detect this from the pathname.
23+
*/
24+
function detectBasePath(): string {
25+
if (typeof window === 'undefined') return '';
26+
27+
// Check if we're running under a known basePath
28+
const pathname = window.location.pathname;
29+
if (pathname.startsWith('/llm-admin')) {
30+
return '/llm-admin';
31+
}
32+
return '';
33+
}
34+
2035
/**
2136
* Fetches runtime configuration from the API route.
2237
* Caches the result for subsequent calls within the same session.
@@ -27,7 +42,9 @@ export async function getConfig(): Promise<RuntimeConfig> {
2742
}
2843

2944
try {
30-
const response = await fetch('/api/config');
45+
// Detect basePath from current URL and prepend to API route
46+
const basePath = detectBasePath();
47+
const response = await fetch(`${basePath}/api/config`);
3148
if (!response.ok) {
3249
throw new Error(`Config fetch failed: ${response.status}`);
3350
}

0 commit comments

Comments
 (0)