diff --git a/frontend/apps/artcraft-website/.env.example b/frontend/apps/artcraft-website/.env.example index fcbd1e317e..c74c3a33be 100644 --- a/frontend/apps/artcraft-website/.env.example +++ b/frontend/apps/artcraft-website/.env.example @@ -2,3 +2,6 @@ # Get the Client ID from the Google Cloud Console: # https://console.cloud.google.com/apis/credentials VITE_GOOGLE_CLIENT_ID=YOUR_CLIENT_ID.apps.googleusercontent.com + +# API backend host. Defaults to https://api.storyteller.ai if unset. +# VITE_API_HOST=http://localhost:12345 diff --git a/frontend/apps/artcraft-website/src/main.tsx b/frontend/apps/artcraft-website/src/main.tsx index d966684c4b..16ce81572b 100644 --- a/frontend/apps/artcraft-website/src/main.tsx +++ b/frontend/apps/artcraft-website/src/main.tsx @@ -11,15 +11,16 @@ const root = ReactDOM.createRoot( document.getElementById("root") as HTMLElement, ); -// In development, route API through the Vite dev server origin to avoid CORS -if (import.meta.env.DEV) { - try { - const origin = window.location.origin; - StorytellerApiHostStore.getInstance().setApiSchemeAndHost(origin); - } catch (e) { - console.warn("Failed to set dev API host override", e); - } -} +// In development, route API through the Vite dev server proxy to avoid CORS, +// unless VITE_API_HOST is explicitly set (eg. for an unsafe browser that ignores CORS). +//if (import.meta.env.DEV && !import.meta.env.VITE_API_HOST) { +// try { +// const origin = window.location.origin; +// StorytellerApiHostStore.getInstance().setApiSchemeAndHost(origin); +// } catch (e) { +// console.warn("Failed to set dev API host override", e); +// } +//} // Cache the referrer immediately — it can change or disappear on navigation. // Only set once so subsequent in-site navigations don't overwrite the original. diff --git a/frontend/libs/api/src/lib/ApiManager.ts b/frontend/libs/api/src/lib/ApiManager.ts index b700008336..883d1c6421 100644 --- a/frontend/libs/api/src/lib/ApiManager.ts +++ b/frontend/libs/api/src/lib/ApiManager.ts @@ -26,7 +26,9 @@ export class ApiManager { } protected getApiSchemeAndHost(): string { - return StorytellerApiHostStore.getInstance().getApiSchemeAndHost(); + const host = StorytellerApiHostStore.getInstance().getApiSchemeAndHost(); + console.log('getSchemaAndHost()', host); + return host; } public async fetch( diff --git a/frontend/libs/api/src/lib/OmniGenApi.ts b/frontend/libs/api/src/lib/OmniGenApi.ts index 85abc21464..072eef82ba 100644 --- a/frontend/libs/api/src/lib/OmniGenApi.ts +++ b/frontend/libs/api/src/lib/OmniGenApi.ts @@ -176,8 +176,10 @@ export class OmniGenApi extends ApiManager { provider?: string, ): Promise { const query = provider ? { provider } : undefined; + const host = this.getApiSchemeAndHost(); + console.log('getImageModels() - host', host); return this.get({ - endpoint: `${this.getApiSchemeAndHost()}/v1/omni_gen/models/image`, + endpoint: `${host}/v1/omni_gen/models/image`, query, }); } @@ -217,8 +219,10 @@ export class OmniGenApi extends ApiManager { public async generateImage( body: OmniGenImageRequest, ): Promise { + const host = this.getApiSchemeAndHost(); + console.log('generateImage() - host', host); return this.post, OmniGenImageGenerateResponse>({ - endpoint: `${this.getApiSchemeAndHost()}/v1/omni_gen/generate/image`, + endpoint: `${host}/v1/omni_gen/generate/image`, body: stripNulls(body), }); } @@ -226,8 +230,10 @@ export class OmniGenApi extends ApiManager { public async generateVideo( body: OmniGenVideoRequest, ): Promise { + const host = this.getApiSchemeAndHost(); + console.log('generateVideo() - host', host); return this.post, OmniGenVideoGenerateResponse>({ - endpoint: `${this.getApiSchemeAndHost()}/v1/omni_gen/generate/video`, + endpoint: `${host}/v1/omni_gen/generate/video`, body: stripNulls(body), }); } diff --git a/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts b/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts index c90da8cb2f..e8100e73ed 100644 --- a/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts +++ b/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts @@ -1,5 +1,8 @@ // Artcraft / Storyteller API backend -const DEFAULT_API_HOST = "https://api.storyteller.ai"; +// Set VITE_API_HOST=http://localhost:12345 for local dev, or leave unset for production. +//const DEFAULT_API_HOST = (import.meta as any).env?.VITE_API_HOST || "https://api.storyteller.ai"; + +const DEFAULT_API_HOST = "http://localhost:12345"; // NB(bt,2025-09-25): 'nx' is creating multiple copies of the library with name // mangling, so the singleton pattern fails to resolve to a single instance.