You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
777 B

  1. import axios from 'axios';
  2. import ready from './ready';
  3. import LinkHeader from './link_header';
  4. export const getLinks = response => {
  5. const value = response.headers.link;
  6. if (!value) {
  7. return { refs: [] };
  8. }
  9. return LinkHeader.parse(value);
  10. };
  11. let csrfHeader = {};
  12. function setCSRFHeader() {
  13. const csrfToken = document.querySelector('meta[name=csrf-token]').content;
  14. csrfHeader['X-CSRF-Token'] = csrfToken;
  15. }
  16. ready(setCSRFHeader);
  17. export default getState => axios.create({
  18. headers: Object.assign(csrfHeader, getState ? {
  19. 'Authorization': `Bearer ${getState().getIn(['meta', 'access_token'], '')}`,
  20. } : {}),
  21. transformResponse: [function (data) {
  22. try {
  23. return JSON.parse(data);
  24. } catch(Exception) {
  25. return data;
  26. }
  27. }],
  28. });