Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions ui/litellm-dashboard/src/components/networking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,34 @@ if (isLocal != true) {
console.log = function () {};
}

const getWindowLocation = () => {
if (typeof window === "undefined") {
return null;
}
return window.location;
};

const updateProxyBaseUrl = (serverRootPath: string, receivedProxyBaseUrl: string | null = null) => {
/**
* Special function for updating the proxy base url. Should only be called by getUiConfig.
*/
const defaultProxyBaseUrl = isLocal ? "http://localhost:4000" : window.location.origin;
let initialProxyBaseUrl = receivedProxyBaseUrl || defaultProxyBaseUrl;
const browserLocation = getWindowLocation();
const resolvedDefaultProxyBaseUrl = isLocal ? "http://localhost:4000" : browserLocation?.origin ?? null;
let initialProxyBaseUrl = receivedProxyBaseUrl || resolvedDefaultProxyBaseUrl;
console.log("proxyBaseUrl:", proxyBaseUrl);
console.log("serverRootPath:", serverRootPath);

if (!initialProxyBaseUrl) {
proxyBaseUrl = proxyBaseUrl ?? null;
console.log("Updated proxyBaseUrl:", proxyBaseUrl);
return;
}

if (serverRootPath.length > 0 && !initialProxyBaseUrl.endsWith(serverRootPath) && serverRootPath != "/") {
initialProxyBaseUrl += serverRootPath;
proxyBaseUrl = initialProxyBaseUrl;
}

proxyBaseUrl = initialProxyBaseUrl;
console.log("Updated proxyBaseUrl:", proxyBaseUrl);
};

Expand All @@ -54,7 +70,11 @@ const updateServerRootPath = (receivedServerRootPath: string) => {
};

export const getProxyBaseUrl = (): string => {
return proxyBaseUrl ? proxyBaseUrl : window.location.origin;
if (proxyBaseUrl) {
return proxyBaseUrl;
}
const browserLocation = getWindowLocation();
return browserLocation?.origin ?? "";
};

const HTTP_REQUEST = {
Expand Down Expand Up @@ -159,7 +179,10 @@ const handleError = async (errorData: string) => {
NotificationsManager.info("UI Session Expired. Logging out.");
lastErrorTime = currentTime;
clearTokenCookies();
window.location.href = window.location.pathname;
const browserLocation = getWindowLocation();
if (browserLocation) {
window.location.href = browserLocation.pathname;
}
}
lastErrorTime = currentTime;
} else {
Expand Down
Loading