使用 CORS 的 React-native JS 调试器问题 - iOS [英] React-native JS Debugger issues with CORS — iOS
问题描述
I am having an issue with the react-native JS debugger on the iOS. The error occurs when I try to debug my app using the JS Debugger tool. I tried different solutions around the web with no success. Has anyone come across this error and managed to fix it?
Replication:
1) Run development app on real iOS device, which loads the JS bundle from http://172.16.23.27.xip.io:8081/index.delta?platform=ios&dev=true&minify=false
2) Enable JS Remote debug tools, which opens http://localhost:8081/debugger-ui/ in Chrome.
3) Bundle reloads, and Chrome DevTools console displays the following error:
Failed to load http://172.16.23.27.xip.io:8081/index.delta?platform=ios&dev=true&minify=false: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. (index):188 Uncaught (in promise) TypeError: Failed to fetch
"react": "16.2.0",
"react-native": "0.52.1"
Try to use http://172.16.23.27.xip.io:8081/debugger-ui/
for debug.
or
open
/node_modules/metro/src/Serverindex.js
find
_processDeltaRequest
mres.setHeader(FILES_CHANGED_COUNT_HEADER, String(output.numModifiedFiles)); mres.setHeader('Content-Type', 'application/javascript'); mres.setHeader('Content-Length', String(Buffer.byteLength(output.bundle))); + mres.setHeader('Access-Control-Allow-Origin', '*'); mres.end(output.bundle);
这篇关于使用 CORS 的 React-native JS 调试器问题 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!