Add site manager and initial validation
[arvados-workbench2.git] / src / common / config.ts
index b7b89bd9e4930100188725b7f117f67abf076587..d801c5fa67b1189278daecb3df0138a7cd4dc5a8 100644 (file)
@@ -35,7 +35,9 @@ export interface Config {
     packageVersion: string;
     parameters: {};
     protocol: string;
-    remoteHosts: string;
+    remoteHosts: {
+        [key: string]: string
+    };
     remoteHostsViaDNS: boolean;
     resources: {};
     revision: string;
@@ -50,6 +52,7 @@ export interface Config {
     websocketUrl: string;
     workbenchUrl: string;
     vocabularyUrl: string;
+    origin: string;
 }
 
 export const fetchConfig = () => {
@@ -59,10 +62,10 @@ export const fetchConfig = () => {
         .catch(() => Promise.resolve(getDefaultConfig()))
         .then(config => Axios
             .get<Config>(getDiscoveryURL(config.API_HOST))
-            .then(response => ({ 
+            .then(response => ({
                 // TODO: After tests delete `|| '/vocabulary-example.json'`
-                config: {...response.data, vocabularyUrl: config.VOCABULARY_URL || '/vocabulary-example.json' }, 
-                apiHost: config.API_HOST, 
+                config: {...response.data, vocabularyUrl: config.VOCABULARY_URL || '/vocabulary-example.json' },
+                apiHost: config.API_HOST,
             })));
 
 };
@@ -96,7 +99,7 @@ export const mockConfig = (config: Partial<Config>): Config => ({
     packageVersion: '',
     parameters: {},
     protocol: '',
-    remoteHosts: '',
+    remoteHosts: {},
     remoteHostsViaDNS: false,
     resources: {},
     revision: '',
@@ -111,6 +114,7 @@ export const mockConfig = (config: Partial<Config>): Config => ({
     websocketUrl: '',
     workbenchUrl: '',
     vocabularyUrl: '',
+    origin: '',
     ...config
 });
 
@@ -124,4 +128,5 @@ const getDefaultConfig = (): ConfigJSON => ({
     VOCABULARY_URL: "",
 });
 
-const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/discovery/v1/apis/arvados/v1/rest`;
+export const DISCOVERY_URL = 'discovery/v1/apis/arvados/v1/rest';
+const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${DISCOVERY_URL}`;