Merge branch '13819-fix-dynamic-url-configuration'
[arvados.git] / src / common / config.ts
index 283bd6db108763bf656d878ed2ceeff51baec42d..775b11452ac370450c89976c5cb88f2fd0883afd 100644 (file)
@@ -10,14 +10,21 @@ export interface Config {
     API_HOST: string;
 }
 
-const defaultConfig: Config = {
-    API_HOST: "https://workbench2.c97qk.arvadosapi.com" // process.env.REACT_APP_ARVADOS_API_HOST || ""
-};
-
 export const fetchConfig = () => {
     return Axios
         .get<Config>(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}`;