From 72664ac2a15440537b362c3f78f68a3a2edb531e Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 20 Aug 2019 15:22:35 +0200
Subject: [PATCH] Add vars to common

---
 packages/common/env.js   | 36 ++++++++++++++++++++++++++++++++++++
 packages/common/utils.js | 16 ++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 packages/common/env.js

diff --git a/packages/common/env.js b/packages/common/env.js
new file mode 100644
index 00000000..a960d881
--- /dev/null
+++ b/packages/common/env.js
@@ -0,0 +1,36 @@
+var config;
+
+switch(process.env.BUILD) {
+    case "development":
+        config = {
+            apiBaseUrl: 'https://mw-dev.tugraz.at',
+            apiUrlPrefix: '',
+            keyCloakClientId: 'auth-dev-mw-frontend',
+        };
+
+        break;
+    case "production":
+        config = {
+            apiBaseUrl: 'https://mw.tugraz.at',
+            apiUrlPrefix: '',
+            keyCloakClientId: 'auth-prod-mw-frontend',
+        };
+        break;
+    case "demo":
+        config = {
+            apiBaseUrl: 'https://api-demo.tugraz.at',
+            apiUrlPrefix: '',
+            keyCloakClientId: 'auth-dev-mw-frontend',
+        };
+        break;
+    case "local":
+    default:
+        config = {
+            apiBaseUrl: 'http://127.0.0.1:8000',
+            apiUrlPrefix: '',
+            keyCloakClientId: 'auth-dev-mw-frontend-local',
+        };
+}
+
+
+export default config;
diff --git a/packages/common/utils.js b/packages/common/utils.js
index 10ae38c9..002d0538 100644
--- a/packages/common/utils.js
+++ b/packages/common/utils.js
@@ -1,3 +1,5 @@
+import env from './env.js';
+
 export default {
     /**
      * Parses a link header
@@ -29,6 +31,20 @@ export default {
         return links;
     },
 
+    /**
+     * Reads a setting
+     *
+     * @param key
+     * @returns {*}
+     */
+    setting: (key) => {
+        return env[key];
+    },
+
+    getAPiUrl: (path = "", withPrefix = true) => {
+        return env.apiBaseUrl + (withPrefix ? vars.apiUrlPrefix : "") + path;
+    },
+
     /**
      * Parses the base url from an url
      *
-- 
GitLab