diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 10:34:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 10:34:04 +0200 |
commit | 979ec02c9a1019152be08705986337e470eabb57 (patch) | |
tree | 6021179ad8649112717a499780f475275af487f2 /src/api | |
parent | refactor: defensive programming to avoid javascript error for unread badges (diff) | |
download | ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.gz ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.zst ferdium-app-979ec02c9a1019152be08705986337e470eabb57.zip |
chore: codebase improvements (#1930)
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/apiBase.ts (renamed from src/api/apiBase.js) | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/api/apiBase.js b/src/api/apiBase.ts index 2fad7eb21..dc10fad91 100644 --- a/src/api/apiBase.js +++ b/src/api/apiBase.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | * Get API base URL from store | 2 | * Get API base URL from store |
3 | */ | 3 | */ |
4 | import { | 4 | import { API_VERSION } from '../environment'; |
5 | API_VERSION, | ||
6 | } from '../environment'; | ||
7 | import { | 5 | import { |
8 | DEV_API_FRANZ_WEBSITE, | 6 | DEV_API_FRANZ_WEBSITE, |
9 | LIVE_FRANZ_API, | 7 | LIVE_FRANZ_API, |
@@ -14,21 +12,25 @@ import { | |||
14 | 12 | ||
15 | // Note: This cannot be used from the internal-server since we are not running within the context of a browser window | 13 | // Note: This cannot be used from the internal-server since we are not running within the context of a browser window |
16 | const apiBase = (withVersion = true) => { | 14 | const apiBase = (withVersion = true) => { |
17 | let url; | 15 | let url: string; |
18 | 16 | ||
19 | if (!window.ferdi | 17 | if ( |
20 | || !window.ferdi.stores.settings | 18 | !(window as any).ferdi || |
21 | || !window.ferdi.stores.settings.all | 19 | !(window as any).ferdi.stores.settings || |
22 | || !window.ferdi.stores.settings.all.app.server) { | 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 | 23 | // Stores have not yet been loaded - return SERVER_NOT_LOADED to force a retry when stores are loaded |
24 | return SERVER_NOT_LOADED; | 24 | return SERVER_NOT_LOADED; |
25 | } | 25 | } |
26 | if (window.ferdi.stores.settings.all.app.server === LOCAL_SERVER) { | 26 | if ((window as any).ferdi.stores.settings.all.app.server === LOCAL_SERVER) { |
27 | // Use URL for local server | 27 | // Use URL for local server |
28 | url = `http://${LOCAL_HOSTNAME}:${window.ferdi.stores.requests.localServerPort}`; | 28 | url = `http://${LOCAL_HOSTNAME}:${ |
29 | (window as any).ferdi.stores.requests.localServerPort | ||
30 | }`; | ||
29 | } else { | 31 | } else { |
30 | // Load URL from store | 32 | // Load URL from store |
31 | url = window.ferdi.stores.settings.all.app.server; | 33 | url = (window as any).ferdi.stores.settings.all.app.server; |
32 | } | 34 | } |
33 | 35 | ||
34 | return withVersion ? `${url}/${API_VERSION}` : url; | 36 | return withVersion ? `${url}/${API_VERSION}` : url; |
@@ -38,5 +40,7 @@ export default apiBase; | |||
38 | 40 | ||
39 | export function termsBase() { | 41 | export function termsBase() { |
40 | // TODO: This needs to handle local vs ferdi vs franz servers | 42 | // TODO: This needs to handle local vs ferdi vs franz servers |
41 | return window.ferdi.stores.settings.all.app.server !== LIVE_FRANZ_API ? window.ferdi.stores.settings.all.app.server : DEV_API_FRANZ_WEBSITE; | 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; | ||
42 | } | 46 | } |