2020-12-10 22:46:27 +01:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('drupalSettings', drupalSettings)
|
|
|
|
console.log(window.location)
|
2020-12-10 22:46:27 +01:00
|
|
|
|
2021-09-16 21:40:18 +02:00
|
|
|
const MGQ = axios.create({
|
2021-03-31 18:42:05 +02:00
|
|
|
baseURL: window.location.origin + '/mgq',
|
2020-12-10 22:46:27 +01:00
|
|
|
withCredentials: true,
|
|
|
|
headers: {
|
2021-03-31 18:42:05 +02:00
|
|
|
Accept: 'application/json',
|
2020-12-10 22:46:27 +01:00
|
|
|
// Accept: 'application/vnd.api+json'
|
|
|
|
// Authorization: 'Basic {token}',
|
2021-03-31 18:42:05 +02:00
|
|
|
'Content-Type': 'application/json'
|
2020-12-10 22:46:27 +01:00
|
|
|
}
|
|
|
|
})
|
2021-09-16 21:40:18 +02:00
|
|
|
|
|
|
|
MGQ.interceptors.response.use(
|
|
|
|
response => {
|
|
|
|
return Promise.resolve(response)
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
const { status } = error.response
|
|
|
|
console.warn('error in graphql-axios', status)
|
|
|
|
if (status === 403) {
|
|
|
|
window.location = '/'
|
|
|
|
}
|
|
|
|
return Promise.reject(error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export default MGQ
|