Rewrite window.fetch method It will not work!
renzhaoz opened this issue · comments
Alex commented
I use it in CRA application , when add token in request hot reload will be not work!
here is the code!
import CloudUtils from './CloudUtils';
const oldFetch = fetch;
const newFetch = (url, options) => {
const token = CloudUtils.getToken();
const headers = options.headers || new Headers();
headers.append('aaaa', `bearer ${token}`);
options.headers = headers;
return oldFetch(`${url}`, options);
};
if (window) {
window.fetch = newFetch;
window.oldFetch = oldFetch;
}