rest-axios.js 782 B

12345678910111213141516171819202122232425262728293031
  1. import axios from 'axios'
  2. // https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
  3. // console.log('drupalSettings', drupalSettings)
  4. // console.log('window.location.origin', window.location.origin)
  5. const REST = axios.create({
  6. baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
  7. withCredentials: true,
  8. headers: {
  9. // Authorization: 'Bearer {token}',
  10. 'Content-Type': 'application/json'
  11. }
  12. })
  13. REST.interceptors.response.use(
  14. response => {
  15. return Promise.resolve(response)
  16. },
  17. error => {
  18. const { status } = error.response
  19. console.warn('error in rest-axios', status)
  20. if (status === 403) {
  21. window.location = '/'
  22. }
  23. return Promise.reject(error)
  24. }
  25. )
  26. export default REST