admin管理员组文章数量:1332345
I currently work on a React-Native mobile app.
The requests to the server API using fetch
works fine, but when I open the "Debug JS Remotely" with Google Chrome, it creates some kind of localhost server and the calls are made from it, and I get the following error from the server API:
XMLHttpRequest cannot load . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.
It's pretty annoying not to be able to track the requests to the server in debug mode.
Any of you have faced a similar issue and do you have a way around it?
Thanks
I currently work on a React-Native mobile app.
The requests to the server API using fetch
works fine, but when I open the "Debug JS Remotely" with Google Chrome, it creates some kind of localhost server and the calls are made from it, and I get the following error from the server API:
XMLHttpRequest cannot load https://my.server./data. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.
It's pretty annoying not to be able to track the requests to the server in debug mode.
Any of you have faced a similar issue and do you have a way around it?
Thanks
Share Improve this question asked Dec 9, 2016 at 14:49 alexmngnalexmngn 9,65720 gold badges75 silver badges136 bronze badges 1- any specific solution to this problem , I am still facing issue with ios only , – Prateek Commented Oct 6, 2017 at 12:59
2 Answers
Reset to default 6I actually found a solution: I installed the Chrome extension Allow-Control-Allow-Origin:*
https://chrome.google./webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
For react-native change your debug url in chrome http://localhost:8081/debugger-ui/ with http://192.168.xxx.xx.xip.io:8081/debugger-ui/
Ex: http://192.168.10.112.xx.xip.io:8081/debugger-ui/
OR
Add
mres.setHeader('Access-Control-Allow-Origin', '*');
to
/node_modules/metro/src/Server\index.js
版权声明:本文标题:javascript - Can't make request to API on React-Native app when Debug JS Remotely is enabled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325887a2453712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论