axios.js 630 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
import axios from 'axios'
import store from '~/store'

// Request interceptor
axios.interceptors.request.use(request => {
request.baseURL = process.env.VUE_APP_BASE_URL

// const token = store.getters['auth/token']
// if (token) {
// request.headers.common.Authorization = `Bearer ${token}`
// }

const locale = store.getters['lang/locale']
if (locale) {
request.headers.common['Accept-Language'] = locale
}

// request.headers['X-Socket-Id'] = Echo.socketId()

return request
})

// Response interceptor
axios.interceptors.response.use(response => response, error => {
return Promise.reject(error)
})