aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/apiBase.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/apiBase.ts')
-rw-r--r--src/api/apiBase.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/api/apiBase.ts b/src/api/apiBase.ts
new file mode 100644
index 000000000..dc10fad91
--- /dev/null
+++ b/src/api/apiBase.ts
@@ -0,0 +1,46 @@
1/**
2 * Get API base URL from store
3 */
4import { API_VERSION } from '../environment';
5import {
6 DEV_API_FRANZ_WEBSITE,
7 LIVE_FRANZ_API,
8 LOCAL_HOSTNAME,
9 LOCAL_SERVER,
10 SERVER_NOT_LOADED,
11} from '../config';
12
13// Note: This cannot be used from the internal-server since we are not running within the context of a browser window
14const apiBase = (withVersion = true) => {
15 let url: string;
16
17 if (
18 !(window as any).ferdi ||
19 !(window as any).ferdi.stores.settings ||
20 !(window as any).ferdi.stores.settings.all ||
21 !(window as any).ferdi.stores.settings.all.app.server
22 ) {
23 // Stores have not yet been loaded - return SERVER_NOT_LOADED to force a retry when stores are loaded
24 return SERVER_NOT_LOADED;
25 }
26 if ((window as any).ferdi.stores.settings.all.app.server === LOCAL_SERVER) {
27 // Use URL for local server
28 url = `http://${LOCAL_HOSTNAME}:${
29 (window as any).ferdi.stores.requests.localServerPort
30 }`;
31 } else {
32 // Load URL from store
33 url = (window as any).ferdi.stores.settings.all.app.server;
34 }
35
36 return withVersion ? `${url}/${API_VERSION}` : url;
37};
38
39export default apiBase;
40
41export function termsBase() {
42 // TODO: This needs to handle local vs ferdi vs franz servers
43 return (window as any).ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API
44 ? (window as any).ferdi.stores.settings.all.app.server
45 : DEV_API_FRANZ_WEBSITE;
46}