From 0e3052e8eb3ba199a5c867e62a6fbfca5c6390e5 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sun, 7 Jan 2018 23:07:41 +0100
Subject: [PATCH] Smarter BACKEND_URL

---
 CHANGELOG                                      | 6 ++++++
 front/src/components/library/radios/Filter.vue | 3 +--
 front/src/config.js                            | 3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 079e3eb4c8..6909d7d788 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,12 @@ Changelog
 ------------------
 
 
+0.3.5 (2018-01-07)
+------------------
+
+- Smarter BACKEND_URL in frontend
+
+
 0.3.4 (2018-01-07)
 ------------------
 
diff --git a/front/src/components/library/radios/Filter.vue b/front/src/components/library/radios/Filter.vue
index 7ed5aa494d..dd170d8b31 100644
--- a/front/src/components/library/radios/Filter.vue
+++ b/front/src/components/library/radios/Filter.vue
@@ -112,9 +112,8 @@ export default {
         selector.push('.autocomplete')
         settings.fields = f.autocomplete_fields
         settings.minCharacters = 1
-        let backendUrl = config.BACKEND_URL || window.location.protocol + '//' + window.location.hostname + ':' + window.location.port
         settings.apiSettings = {
-          url: backendUrl + f.autocomplete + '?' + f.autocomplete_qs,
+          url: config.BACKEND_URL + f.autocomplete + '?' + f.autocomplete_qs,
           beforeXHR: function (xhrObject) {
             xhrObject.setRequestHeader('Authorization', self.$store.getters['auth/header'])
             return xhrObject
diff --git a/front/src/config.js b/front/src/config.js
index 5bc5c160e5..3ba1247acf 100644
--- a/front/src/config.js
+++ b/front/src/config.js
@@ -1,6 +1,9 @@
 class Config {
   constructor () {
     this.BACKEND_URL = process.env.BACKEND_URL
+    if (this.BACKEND_URL === '/') {
+      this.BACKEND_URL = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port
+    }
     if (!this.BACKEND_URL.endsWith('/')) {
       this.BACKEND_URL += '/'
     }
-- 
GitLab