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

46 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

import axios from 'axios'
2019-04-10 10:47:45 +02:00
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
// console.log('drupalSettings', drupalSettings)
// console.log('window.location.origin', window.location.origin)
2021-09-21 11:05:29 +02:00
// axios.interceptors.response.use(
// response => {
// return Promise.resolve(response)
// },
// error => {
// const { status } = error.response
// console.warn('error in rest-axios', status)
// if (status === 403) {
// window.location = '/'
// }
// return Promise.reject(error)
// }
// )
const REST = axios.create({
baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
2019-05-21 16:42:36 +02:00
withCredentials: true,
headers: {
// Authorization: 'Bearer {token}',
'Content-Type': 'application/json'
}
})
REST.interceptors.response.use(
response => {
return Promise.resolve(response)
},
error => {
const { status } = error.response
console.warn('error in rest-axios', status)
if (status === 403) {
window.location = '/'
}
return Promise.reject(error)
}
)
export default REST