graphql-axios.js 789 B

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