Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): make deployment base runtime-safe

joshistoast99993d1400e5
diff --git a/invokeai/frontend/webv2/src/platform/transport/deploymentBase.ts b/invokeai/frontend/webv2/src/platform/transport/deploymentBase.ts
index 569a55fb5a..1798b33911 100644
--- a/invokeai/frontend/webv2/src/platform/transport/deploymentBase.ts
+++ b/invokeai/frontend/webv2/src/platform/transport/deploymentBase.ts
@@ -27,9 +27,12 @@ export const deriveDeploymentBaseUrl = (
let cachedDeploymentBaseUrl: string | undefined;
+const getRuntimeOrigin = (): string => (typeof window === 'undefined' ? 'http://localhost' : window.location.origin);
+
/** Deployment origin plus prefix, without a trailing slash. */
export const getDeploymentBaseUrl = (): string => {
- cachedDeploymentBaseUrl ??= deriveDeploymentBaseUrl(import.meta.url, window.location.origin);
+ const runtimeOrigin = getRuntimeOrigin();
+ cachedDeploymentBaseUrl ??= deriveDeploymentBaseUrl(import.meta.url, runtimeOrigin, runtimeOrigin);
return cachedDeploymentBaseUrl;
};
diff --git a/invokeai/frontend/webv2/src/platform/transport/http.ts b/invokeai/frontend/webv2/src/platform/transport/http.ts
index 4a6d48c6a6..9a3a050e5d 100644
--- a/invokeai/frontend/webv2/src/platform/transport/http.ts
+++ b/invokeai/frontend/webv2/src/platform/transport/http.ts
@@ -30,7 +30,7 @@ export const getHttpAuthToken = (): string | null => authAdapter.getToken();
export const getBackendSocketUrl = (): string => {
const baseUrl = API_BASE_URL || getDeploymentBaseUrl();
- return new URL(baseUrl, window.location.origin).origin;
+ return new URL(baseUrl, getDeploymentBaseUrl()).origin;
};
export const getBackendSocketPath = (): string => {
@@ -38,7 +38,7 @@ export const getBackendSocketPath = (): string => {
return `${getDeploymentBasePath()}/ws/socket.io`;
}
- const pathname = new URL(API_BASE_URL, window.location.origin).pathname.replace(/\/$/, '');
+ const pathname = new URL(API_BASE_URL, getDeploymentBaseUrl()).pathname.replace(/\/$/, '');
return `${pathname === '/' ? '' : pathname}/ws/socket.io`;
};