json-axios.js 768 B

1234567891011121314151617181920212223242526272829303132
  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)
  5. const JSONAPI = axios.create({
  6. baseURL: window.location.origin+`/jsonapi`,
  7. withCredentials: true,
  8. headers: {
  9. Accept: 'application/vnd.api+json'
  10. // Authorization: 'Basic {token}',
  11. // 'Content-Type': 'application/json'
  12. }
  13. })
  14. JSONAPI.interceptors.response.use(
  15. response => {
  16. return Promise.resolve(response)
  17. },
  18. error => {
  19. const { status } = error.response
  20. console.warn('error in json-axios', status)
  21. if (status === 403) {
  22. window.location = '/'
  23. }
  24. return Promise.reject(error)
  25. }
  26. )
  27. export default JSONAPI