From 60929892a896449bdefdb9850da2eb08067773cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20Borbo=C3=ABn?= <ponsfrilus@gmail.com>
Date: Thu, 21 Jan 2021 19:06:16 +0100
Subject: [PATCH] [feature] project config

---
 canapGEST/Site/src/config/index.js               | 11 +++++++++++
 canapGEST/Site/src/plugins/axios.js              |  5 ++++-
 canapGEST/Site/src/store/modules/user/actions.js |  5 ++++-
 3 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 canapGEST/Site/src/config/index.js

diff --git a/canapGEST/Site/src/config/index.js b/canapGEST/Site/src/config/index.js
new file mode 100644
index 0000000..a585344
--- /dev/null
+++ b/canapGEST/Site/src/config/index.js
@@ -0,0 +1,11 @@
+'use strict'
+// https://stackoverflow.com/questions/44750008/vuejs-configuration-using-a-global-variable
+module.exports = {
+  'API_LOCATION': process.env.NODE_ENV === 'production'
+    ? 'https://canap-gest.epfl.ch/api'
+    : 'http://localhost:8181/api',
+  'LOGIN_REDIRECT': process.env.NODE_ENV === 'production'
+    ? 'https://canap-gest.epfl.ch/api/auth/login'
+    : 'http://localhost:8181/api/auth/login',
+
+}
diff --git a/canapGEST/Site/src/plugins/axios.js b/canapGEST/Site/src/plugins/axios.js
index 92c3b23..fdf6b6c 100644
--- a/canapGEST/Site/src/plugins/axios.js
+++ b/canapGEST/Site/src/plugins/axios.js
@@ -1,10 +1,13 @@
 import axios from 'axios'
 import store from '@/store/store.js'
 import router from '@/router/index.js'
+import config from '../config'
 
 const instance = axios.create({
   headers: { 'Authorization': "Bearer " + localStorage.getItem('stored_token') },
-  baseURL: 'https://canap-gest.epfl.ch/api'
+  // baseURL: 'https://canap-gest.epfl.ch/api'
+  // baseURL: 'http://localhost:8181/api'
+  baseURL: config.API_LOCATION
 })
 
 instance.interceptors.response.use(function (response) {
diff --git a/canapGEST/Site/src/store/modules/user/actions.js b/canapGEST/Site/src/store/modules/user/actions.js
index 7c37f26..d3660d1 100644
--- a/canapGEST/Site/src/store/modules/user/actions.js
+++ b/canapGEST/Site/src/store/modules/user/actions.js
@@ -1,4 +1,5 @@
 import axios from '../../../plugins/axios'
+import config from '../../../config'
 
 export function login (context, key) {
   if (key) {
@@ -8,7 +9,9 @@ export function login (context, key) {
     })
   }
   else {
-    window.location.href = "https://canap-gest.epfl.ch/api/auth/login"
+    //window.location.href = "https://canap-gest.epfl.ch/api/auth/login"
+    //window.location.href = "http://localhost:8181/api/auth/login"
+    window.location.href = config.LOGIN_REDIRECT
   }
 }
 
-- 
GitLab