| 24 | } |
| 25 | |
| 26 | export default function fetch(url: string, options: any, absolutePath = false) { |
| 27 | const contentType = get(options, 'headers.Content-Type'); |
| 28 | |
| 29 | let headers: any = { |
| 30 | }; |
| 31 | |
| 32 | const tk = localStorage.getItem('accessToken'); |
| 33 | if (tk && tk !== 'undefined') { |
| 34 | headers.Authorization = `CodeDog ${tk}`; |
| 35 | } |
| 36 | |
| 37 | if (contentType) { |
| 38 | headers = { |
| 39 | ...headers, |
| 40 | 'Content-Type': contentType, |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | options.headers = appendXSRFTokenHeader(headers); |
| 45 | |
| 46 | return window.fetch(`${absolutePath ? '' : window.location.origin}${url}`, options); |
| 47 | } |