X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/22152102405a1407355d42a32385efd0d83bbc9c..65d436f7c4bd643c7b6cccf97001ff6aef2c896b:/src/common/config.ts diff --git a/src/common/config.ts b/src/common/config.ts index 4b4a52a3ea..250c806c69 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import Axios from "../../node_modules/axios"; +import Axios from "axios"; export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json"; @@ -10,14 +10,21 @@ export interface Config { API_HOST: string; } -const defaultConfig: Config = { - API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "" -}; - export const fetchConfig = () => { return Axios .get(CONFIG_URL + "?nocache=" + (new Date()).getTime()) .then(response => response.data) - .catch(() => Promise.resolve(defaultConfig)); + .catch(() => Promise.resolve(getDefaultConfig())) + .then(mapConfig); }; +const mapConfig = (config: Config): Config => ({ + ...config, + API_HOST: addProtocol(config.API_HOST) +}); + +const getDefaultConfig = (): Config => ({ + API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "" +}); + +const addProtocol = (url: string) => `${window.location.protocol}//${url}`;