Implement configuration fetching during runtime
[arvados-workbench2.git] / src / common / config.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import Axios from "../../node_modules/axios";
6
7 export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
8
9 export interface Config {
10     API_HOST: string;
11 }
12
13 const defaultConfig: Config = {
14     API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || ""
15 };
16
17 export const fetchConfig = () => {
18     return Axios
19         .get<Config>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
20         .then(response => response.data)
21         .catch(() => Promise.resolve(defaultConfig));
22 };
23