使用CORS的React-native JS Debugger问题— iOS [英] React-native JS Debugger issues with CORS — iOS

查看:183
本文介绍了使用CORS的React-native JS Debugger问题— iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上的本机JS调试器遇到问题.当我尝试使用JS调试器工具调试应用程序时,发生错误.我在网络上尝试了不同的解决方案,但都没有成功.有没有人遇到此错误并设法解决该错误?

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?

复制:

1)在真正的iOS设备上运行开发应用程序,该应用程序可从

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)启用JS远程调试工具,该工具将打开 http://localhost:8081/debugger-ui/在Chrome中.

2) Enable JS Remote debug tools, which opens http://localhost:8081/debugger-ui/ in Chrome.

3)重新加载捆绑包,Chrome DevTools控制台显示以下错误:

3) Bundle reloads, and Chrome DevTools console displays the following error:

无法加载 http://172.16.23.27.xip.io:8081/index.delta?platform=ios&dev=true&minify=false :在请求的请求中不存在"Access-Control-Allow-Origin"标头资源.因此,不允许访问来源' http://localhost:8081 .如果不透明的响应满足您的需求,请将请求的模式设置为"no-cors",以在禁用CORS的情况下获取资源. (索引):188未捕获(已承诺)TypeError:无法获取

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"

推荐答案

尝试使用http://172.16.23.27.xip.io:8081/debugger-ui/进行调试.

  1. 打开/node_modules/metro/src/Server\index.js

找到_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 Debugger问题— iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆