materio-d9/web/themes/custom/materiotheme/vuejs/api/json-axios.js

33 lines
768 B
JavaScript
Raw Normal View History

import axios from 'axios'
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
// console.log('drupalSettings', drupalSettings)
console.log(window.location)
const JSONAPI = axios.create({
2019-05-21 15:54:27 +02:00
baseURL: window.location.origin+`/jsonapi`,
2019-05-21 16:42:36 +02:00
withCredentials: true,
headers: {
Accept: 'application/vnd.api+json'
2019-05-21 16:42:36 +02:00
// Authorization: 'Basic {token}',
// 'Content-Type': 'application/json'
}
})
JSONAPI.interceptors.response.use(
response => {
return Promise.resolve(response)
},
error => {
const { status } = error.response
console.warn('error in json-axios', status)
if (status === 403) {
window.location = '/'
}
return Promise.reject(error)
}
)
export default JSONAPI