From 789c04a8e84ea43a19bbdaa35a5a0c7909795b75 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 15 Apr 2019 18:00:32 +0200 Subject: [PATCH] centralized API-URL in quasar.conf.js --- frontend/quasar.conf.js | 10 +++++++++- frontend/src/boot/axios.js | 11 ++++++++++- frontend/src/pages/Overview.vue | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index b557976..f95dbf8 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -100,7 +100,15 @@ module.exports = function (ctx) { loader: 'eslint-loader', exclude: /node_modules/ }) - } + }, + env: ctx.dev + ? { // Base URL for API-Calls: DEV + API: JSON.stringify('http://localhost:8080') + } + : { // Base URL for API-Calls: PRODUCTION (build) + API: JSON.stringify('http://se.hs-heilbronn.de:8090') + //API: JSON.stringify('http://se.hs-heilbronn.de:8090') + } }, devServer: { diff --git a/frontend/src/boot/axios.js b/frontend/src/boot/axios.js index 7ada677..8523d48 100644 --- a/frontend/src/boot/axios.js +++ b/frontend/src/boot/axios.js @@ -1,5 +1,14 @@ import axios from "axios"; +const axiosInstance = axios.create({ + baseURL: process.env.API +}); +console.log("process.env.DEV: "+process.env.DEV); +console.log("process.env.API: "+process.env.API); + export default async ({ Vue }) => { - Vue.prototype.$axios = axios; + //Vue.prototype.$axios = axios; + Vue.prototype.$axios = axiosInstance; }; + +export { axiosInstance } diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index bb66a29..0831ffa 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -113,7 +113,7 @@ }, methods: { fetchAllCaches() { - this.$axios.get('http://localhost:8080/api/allCaches') + this.$axios.get('/api/allCaches') .then((response) => { console.log("Caches: " + this.caches); this.caches = response.data; @@ -126,7 +126,7 @@ }, deleteCache(id) { console.log('delete cache: ' + id) - this.$axios.delete('http://localhost:8080/api/deleteCache', {params: {cacheID: id}}) + this.$axios.delete('/api/deleteCache', {params: {cacheID: id}}) .then((response) => { this.fetchAllCaches() })