aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/apiBase.js
blob: 961414668999a66ebe13e56bd6d03803e46e4752 (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
/**
 * Get API base URL from store
 */
import {
  API_VERSION
} from '../environment';

const apiBase = () => {
  let url;
  if (!window.ferdi.stores.settings) {
    // Stores have not yet been loaded - send invalid URL to force a retry when stores are loaded
    url = 'https://localhost:9999';
  } else if (window.ferdi.stores.settings.all.app.server) {
    // Load URL from store
    url = window.ferdi.stores.settings.all.app.server;
  } else {
    // Use default server url
    url = SERVER_URL;
  }

  return `${url}/${API_VERSION}`;
}

export default apiBase