| 1 |
import axios from 'axios' |
| 2 |
|
| 3 |
const Axios = axios.create({ |
| 4 |
baseURL: window.extAssistData.root, |
| 5 |
headers: { |
| 6 |
'X-WP-Nonce': window.extAssistData.nonce, |
| 7 |
'X-Requested-With': 'XMLHttpRequest', |
| 8 |
'X-Extendify-Assist': true, |
| 9 |
'X-Extendify': true, |
| 10 |
}, |
| 11 |
}) |
| 12 |
Axios.interceptors.request.use( |
| 13 |
(request) => { |
| 14 |
// Thiis is here to limit network requests when encountering aggressive rate limiting |
| 15 |
const q = new URLSearchParams(window.location.search) |
| 16 |
if (['onboarding'].includes(q.get('extendify'))) { |
| 17 |
throw new axios.Cancel( |
| 18 |
'Assist is not available while running Launch', |
| 19 |
) |
| 20 |
} |
| 21 |
return checkDevMode(request) |
| 22 |
}, |
| 23 |
(error) => error, |
| 24 |
) |
| 25 |
Axios.interceptors.response.use((response) => |
| 26 |
Object.prototype.hasOwnProperty.call(response, 'data') |
| 27 |
? response.data |
| 28 |
: response, |
| 29 |
) |
| 30 |
|
| 31 |
const checkDevMode = (request) => { |
| 32 |
request.headers['X-Extendify-Assist-Dev-Mode'] = |
| 33 |
window.location.search.indexOf('DEVMODE') > -1 |
| 34 |
request.headers['X-Extendify-Assist-Local-Mode'] = |
| 35 |
window.location.search.indexOf('LOCALMODE') > -1 |
| 36 |
return request |
| 37 |
} |
| 38 |
|
| 39 |
export { Axios } |
| 40 |
|