Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite window.fetch method It will not work! #783

Open
renzhaoz opened this issue Nov 1, 2023 · 0 comments
Open

Rewrite window.fetch method It will not work! #783

renzhaoz opened this issue Nov 1, 2023 · 0 comments

Comments

@renzhaoz
Copy link

renzhaoz commented Nov 1, 2023

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant