X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e6039bec0497aa7e1391958e5c4f84bbaeef653e..c11055f2d6ce8385088bc221eab1175e31777ec0:/src/common/config.ts diff --git a/src/common/config.ts b/src/common/config.ts index 4b4a52a3ea..492328d986 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -2,22 +2,32 @@ // // 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"; export interface Config { - API_HOST: string; + apiHost: string; + keepWebHost: 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, + apiHost: addProtocol(config.apiHost), + keepWebHost: addProtocol(config.keepWebHost) +}); + +const getDefaultConfig = (): Config => ({ + apiHost: process.env.REACT_APP_ARVADOS_API_HOST || "", + keepWebHost: process.env.REACT_APP_ARVADOS_KEEP_WEB_HOST || "" +}); + +const addProtocol = (url: string) => `${window.location.protocol}//${url}`;