blob: 561b025f00e5f802e19561d2278ea49ccaa3bda2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/**
* Get API base URL from store
*/
import {
API_VERSION,
} from '../environment';
import {
LOCAL_SERVER,
} from '../config';
const apiBase = () => {
let url;
if (!window.ferdi
|| !window.ferdi.stores.settings
|| !window.ferdi.stores.settings.all
|| !window.ferdi.stores.settings.all.app.server) {
// Stores have not yet been loaded - send invalid URL to force a retry when stores are loaded
// "Why 1.1.1.1 as the default, invalid URL?"
// 1.1.1.1 is the server for Cloudflare's DNS service and will be the same across most networks.
// Using a random IP could result in unwanted connections, using localhost could unwantedly
// connect to local develoment servers.
// 1.1.1.1 also sends a status 400 response for invalid routes. Other servers may return status 401
// on some routes. This would result in Ferdi deleting its current authToken as it thinks it
// has gone invalid.
url = 'https://1.1.1.1';
} else if (window.ferdi.stores.settings.all.app.server === LOCAL_SERVER) {
// Use URL for local server
url = `http://127.0.0.1:${window.ferdi.stores.requests.localServerPort}`;
} else {
// Load URL from store
url = window.ferdi.stores.settings.all.app.server;
}
return `${url}/${API_VERSION}`;
};
export default apiBase;
|