Skip to content

Commit b1f3553

Browse files
committed
Update networking.tsx
1 parent 00f61b2 commit b1f3553

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

ui/litellm-dashboard/src/components/networking.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,34 @@ if (isLocal != true) {
3434
console.log = function () {};
3535
}
3636

37+
const getWindowLocation = () => {
38+
if (typeof window === "undefined") {
39+
return null;
40+
}
41+
return window.location;
42+
};
43+
3744
const updateProxyBaseUrl = (serverRootPath: string, receivedProxyBaseUrl: string | null = null) => {
3845
/**
3946
* Special function for updating the proxy base url. Should only be called by getUiConfig.
4047
*/
41-
const defaultProxyBaseUrl = isLocal ? "http://localhost:4000" : window.location.origin;
42-
let initialProxyBaseUrl = receivedProxyBaseUrl || defaultProxyBaseUrl;
48+
const browserLocation = getWindowLocation();
49+
const resolvedDefaultProxyBaseUrl = isLocal ? "http://localhost:4000" : browserLocation?.origin ?? null;
50+
let initialProxyBaseUrl = receivedProxyBaseUrl || resolvedDefaultProxyBaseUrl;
4351
console.log("proxyBaseUrl:", proxyBaseUrl);
4452
console.log("serverRootPath:", serverRootPath);
53+
54+
if (!initialProxyBaseUrl) {
55+
proxyBaseUrl = proxyBaseUrl ?? null;
56+
console.log("Updated proxyBaseUrl:", proxyBaseUrl);
57+
return;
58+
}
59+
4560
if (serverRootPath.length > 0 && !initialProxyBaseUrl.endsWith(serverRootPath) && serverRootPath != "/") {
4661
initialProxyBaseUrl += serverRootPath;
47-
proxyBaseUrl = initialProxyBaseUrl;
4862
}
63+
64+
proxyBaseUrl = initialProxyBaseUrl;
4965
console.log("Updated proxyBaseUrl:", proxyBaseUrl);
5066
};
5167

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

5672
export const getProxyBaseUrl = (): string => {
57-
return proxyBaseUrl ? proxyBaseUrl : window.location.origin;
73+
if (proxyBaseUrl) {
74+
return proxyBaseUrl;
75+
}
76+
const browserLocation = getWindowLocation();
77+
return browserLocation?.origin ?? "";
5878
};
5979

6080
const HTTP_REQUEST = {
@@ -159,7 +179,10 @@ const handleError = async (errorData: string) => {
159179
NotificationsManager.info("UI Session Expired. Logging out.");
160180
lastErrorTime = currentTime;
161181
clearTokenCookies();
162-
window.location.href = window.location.pathname;
182+
const browserLocation = getWindowLocation();
183+
if (browserLocation) {
184+
window.location.href = browserLocation.pathname;
185+
}
163186
}
164187
lastErrorTime = currentTime;
165188
} else {

0 commit comments

Comments
 (0)