2019-04-09 00:21:00 +02:00
|
|
|
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
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('drupalSettings', drupalSettings)
|
2021-03-31 19:17:55 +02:00
|
|
|
// console.log('window.location.origin', window.location.origin)
|
2019-04-09 00:21:00 +02:00
|
|
|
|
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)
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
|
2021-09-16 21:40:18 +02:00
|
|
|
const REST = axios.create({
|
2021-03-31 22:00:37 +02:00
|
|
|
baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
|
2019-05-21 16:42:36 +02:00
|
|
|
withCredentials: true,
|
2019-04-09 00:21:00 +02:00
|
|
|
headers: {
|
2019-05-21 17:00:14 +02:00
|
|
|
// Authorization: 'Bearer {token}',
|
2021-03-31 18:42:05 +02:00
|
|
|
'Content-Type': 'application/json'
|
2019-04-09 00:21:00 +02:00
|
|
|
}
|
|
|
|
})
|
2021-09-16 21:40:18 +02:00
|
|
|
|
|
|
|
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
|