Merge pull request #2319 from jeromelebleu/frontend-api-base-url

Proxify API requests in Vue's development server
This commit is contained in:
Antoine Nguyen
2021-07-13 12:00:54 +02:00
committed by GitHub
4 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
{
"API_BASE_URL": "http://localhost:8000/api/v2"
"API_BASE_URL": "/api/v2/"
}
-2
View File
@@ -1,4 +1,3 @@
import Vue from 'vue'
import axios from 'axios'
import Cookies from 'js-cookie'
@@ -10,7 +9,6 @@ const _axios = axios.create()
_axios.interceptors.request.use(
function (config) {
// Do something before request is sent
config.baseURL = Vue.prototype.$config.API_BASE_URL
if (store.state.auth.isAuthenticated) {
config.headers['Accept-Language'] = store.state.auth.authUser.language
}
+7
View File
@@ -8,6 +8,7 @@ import router from './router'
import store from './store'
import vuetify from './plugins/vuetify'
import sassStyles from './styles/global.scss' // eslint-disable-line no-unused-vars
import repository from './api/repository'
Vue.config.productionTip = false
@@ -15,7 +16,13 @@ export const bus = new Vue()
fetch(process.env.BASE_URL + 'config.json').then(resp => {
resp.json().then((config) => {
if (!config.API_BASE_URL) {
throw Error('API_BASE_URL is not defined in config.json')
}
repository.defaults.baseURL = config.API_BASE_URL
Vue.prototype.$config = config
new Vue({
router,
store,
+7
View File
@@ -1,4 +1,11 @@
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:8000/'
}
}
},
transpileDependencies: [
'vuetify'
]