@@ -34,18 +34,34 @@ if (isLocal != true) {
34
34
console . log = function ( ) { } ;
35
35
}
36
36
37
+ const getWindowLocation = ( ) => {
38
+ if ( typeof window === "undefined" ) {
39
+ return null ;
40
+ }
41
+ return window . location ;
42
+ } ;
43
+
37
44
const updateProxyBaseUrl = ( serverRootPath : string , receivedProxyBaseUrl : string | null = null ) => {
38
45
/**
39
46
* Special function for updating the proxy base url. Should only be called by getUiConfig.
40
47
*/
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 ;
43
51
console . log ( "proxyBaseUrl:" , proxyBaseUrl ) ;
44
52
console . log ( "serverRootPath:" , serverRootPath ) ;
53
+
54
+ if ( ! initialProxyBaseUrl ) {
55
+ proxyBaseUrl = proxyBaseUrl ?? null ;
56
+ console . log ( "Updated proxyBaseUrl:" , proxyBaseUrl ) ;
57
+ return ;
58
+ }
59
+
45
60
if ( serverRootPath . length > 0 && ! initialProxyBaseUrl . endsWith ( serverRootPath ) && serverRootPath != "/" ) {
46
61
initialProxyBaseUrl += serverRootPath ;
47
- proxyBaseUrl = initialProxyBaseUrl ;
48
62
}
63
+
64
+ proxyBaseUrl = initialProxyBaseUrl ;
49
65
console . log ( "Updated proxyBaseUrl:" , proxyBaseUrl ) ;
50
66
} ;
51
67
@@ -54,7 +70,11 @@ const updateServerRootPath = (receivedServerRootPath: string) => {
54
70
} ;
55
71
56
72
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 ?? "" ;
58
78
} ;
59
79
60
80
const HTTP_REQUEST = {
@@ -159,7 +179,10 @@ const handleError = async (errorData: string) => {
159
179
NotificationsManager . info ( "UI Session Expired. Logging out." ) ;
160
180
lastErrorTime = currentTime ;
161
181
clearTokenCookies ( ) ;
162
- window . location . href = window . location . pathname ;
182
+ const browserLocation = getWindowLocation ( ) ;
183
+ if ( browserLocation ) {
184
+ window . location . href = browserLocation . pathname ;
185
+ }
163
186
}
164
187
lastErrorTime = currentTime ;
165
188
} else {
0 commit comments