diff options
Diffstat (limited to 'src/api/apiBase.js')
-rw-r--r-- | src/api/apiBase.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/api/apiBase.js b/src/api/apiBase.js new file mode 100644 index 000000000..e8d571171 --- /dev/null +++ b/src/api/apiBase.js | |||
@@ -0,0 +1,32 @@ | |||
1 | /** | ||
2 | * Get API base URL from store | ||
3 | */ | ||
4 | import { | ||
5 | API_VERSION, | ||
6 | } from '../environment'; | ||
7 | |||
8 | const apiBase = () => { | ||
9 | let url; | ||
10 | |||
11 | if (!window.ferdi | ||
12 | || !window.ferdi.stores.settings | ||
13 | || !window.ferdi.stores.settings.all | ||
14 | || !window.ferdi.stores.settings.all.app.server) { | ||
15 | // Stores have not yet been loaded - send invalid URL to force a retry when stores are loaded | ||
16 | // "Why 1.1.1.1 as the default, invalid URL?" | ||
17 | // 1.1.1.1 is the server for Cloudflare's DNS service and will be the same across most networks. | ||
18 | // Using a random IP could result in unwanted connections, using localhost could unwantedly | ||
19 | // connect to local develoment servers. | ||
20 | // 1.1.1.1 also sends a status 400 response for invalid routes. Other servers may return status 401 | ||
21 | // on some routes. This would result in Ferdi deleting its current authToken as it thinks it | ||
22 | // has gone invalid. | ||
23 | url = 'https://1.1.1.1'; | ||
24 | } else { | ||
25 | // Load URL from store | ||
26 | url = window.ferdi.stores.settings.all.app.server; | ||
27 | } | ||
28 | |||
29 | return `${url}/${API_VERSION}`; | ||
30 | }; | ||
31 | |||
32 | export default apiBase; | ||