fix: Chat UI 404 when navigating to conversation

getChatUrl() hardcoded /ui/chat which does not exist as a Next.js
route in dev mode. Use NEXT_PUBLIC_BASE_URL to determine the correct
prefix (/chat in dev, /ui/chat in production).

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-03-07 06:24:26 +00:00
parent efe079de23
commit 5b37b361d3

View file

@ -49,10 +49,18 @@ function getGreeting(): string {
return "Good evening";
}
// Build the chat UI URL respecting server root path (e.g. /litellm/ui/chat)
// Build the chat UI URL respecting server root path and basePath.
// In dev mode (Next.js dev server), routes live at /chat directly.
// When served by the proxy, static export is mounted under /ui, so the path
// becomes {serverRootPath}/ui/chat. Use NEXT_PUBLIC_BASE_URL to detect the
// prefix so the same code works in both environments.
function getChatUrl(id?: string): string {
const base = process.env.NEXT_PUBLIC_BASE_URL ?? "";
const trimmed = base.replace(/^\/+|\/+$/g, "");
const uiPath = trimmed ? `/${trimmed}` : "";
const root = serverRootPath && serverRootPath !== "/" ? serverRootPath.replace(/\/+$/, "") : "";
return id ? `${root}/ui/chat?id=${id}` : `${root}/ui/chat`;
const prefix = `${root}${uiPath}`;
return id ? `${prefix}/chat?id=${id}` : `${prefix}/chat`;
}
// Build the dashboard root URL