2

I am using the Fetch API in my React+Redux app like this:

fetch("http://news.at.zhihu.com/api/4/news/before/20160127").

The app is running in Chrome and I also set the --disable-web-security argument when I open Chrome. However, I still get the CORS issue:

Fetch API cannot load http://news.at.zhihu.com/api/4/news/before/20160127. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

If I use XMLHTTPRequest, it works well. It looks like that the --disable-web-security can not work well with Fetch API.

Does anyone know how to use Fetch API without worrying about CORS issue? I can not modify response header such as 'Access-Control-Allow-Origin' since the services are not in my charge.

Jeremy
  • 1
  • 85
  • 340
  • 366
Jason Xu
  • 845
  • 8
  • 22
  • you could use a fetch polyfill... – dandavis Jan 27 '16 at 07:39
  • @dandavis In fact ,I am using the fetch polyfill of 'isomorphic-fetch'. It has the issue mentioned above. – Jason Xu Jan 28 '16 at 02:21
  • you'd have to mod it to get chrome to ignore the native fetch()... i can't see it on github ATM... – dandavis Jan 28 '16 at 02:23
  • @dandavis Could you give me a detailed example of how to do it, please? – Jason Xu Jan 28 '16 at 02:28
  • ex: on https://github.com/github/fetch/blob/master/fetch.js , replace each instance of "fetch" with "fitch", then use "fitch" in your code, or simply comment out line 5 of that file and let it clobber chrome's built-in fetch(). – dandavis Jan 28 '16 at 02:50

0 Answers0