mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-01 16:08:30 +00:00
website dynamically targets development in dev mode (#1387)
This commit is contained in:
1 parent
fc3423d05e
commit
ec991185c6
2 files changed
+20
-4
No files matched your search
@@ -14,8 +14,7 @@ const root = ReactDOM.createRoot(
|
||||
// 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);
|
||||
StorytellerApiHostStore.getInstance().setDevelopment();
|
||||
} catch (e) {
|
||||
console.warn("Failed to set dev API host override", e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Artcraft / Storyteller API backend
|
||||
const DEFAULT_API_HOST = "https://api.storyteller.ai";
|
||||
const DEFAULT_API_HOST_PRODUCTION = "https://api.storyteller.ai";
|
||||
const DEFAULT_API_HOST_DEVELOPMENT = "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.
|
||||
@@ -32,7 +34,7 @@ export class StorytellerApiHostStore {
|
||||
if ((window as any).STORYTELLER_API_HOST_STORE !== undefined) {
|
||||
return (window as any).STORYTELLER_API_HOST_STORE;
|
||||
}
|
||||
const instance = new StorytellerApiHostStore(DEFAULT_API_HOST);
|
||||
const instance = new StorytellerApiHostStore(DEFAULT_API_HOST_PRODUCTION);
|
||||
(window as any).STORYTELLER_API_HOST_STORE = instance;
|
||||
return instance;
|
||||
}
|
||||
@@ -43,6 +45,21 @@ export class StorytellerApiHostStore {
|
||||
return this.apiSchemeAndHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* This mutates the singleton instance to target development.
|
||||
*/
|
||||
public setDevelopment() {
|
||||
console.warn("StorytellerApiHostStore.setDevelopment() - all calls will target development");
|
||||
this.apiSchemeAndHost = DEFAULT_API_HOST_DEVELOPMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* This mutates the singleton instance to target production.
|
||||
*/
|
||||
public setProduction() {
|
||||
this.apiSchemeAndHost = DEFAULT_API_HOST_PRODUCTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Externally update the API host.
|
||||
* This is used to sync with Tauri for enabling easier development.
|
||||
|
||||
Reference in new issue
Block a user