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

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

export default apiBase;