ngrok尝试连接到React开发服务器时无效的主机头 [英] Invalid Host Header when ngrok tries to connect to React dev server

查看:233
本文介绍了ngrok尝试连接到React开发服务器时无效的主机头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在移动设备上测试我的React应用程序.我正在使用ngrok使本地服务器可用于其他设备,并且已将其与多种其他应用程序一起使用.但是,当我尝试将ngrok连接到React开发服务器时,出现错误:

I'm trying to test my React application on a mobile device. I'm using ngrok to make my local server available to other devices and have gotten this working with a variety of other applications. However, when I try to connect ngrok to the React dev server, I get the error:

Invalid Host Header 

我相信默认情况下,React会阻止来自其他来源的所有请求.有什么想法吗?

I believe that React blocks all requests from another source by default. Any thoughts?

推荐答案

我遇到了类似的问题,发现有两种解决方案,它们可以直接在浏览器中查看应用程序

I'm encountering a similar issue and found two solutions that work as far as viewing the application directly in a browser

ngrok http 8080 -host-header="localhost:8080"
ngrok http --host-header=rewrite 8080

显然用您正在运行的任何端口替换8080

obviously replace 8080 with whatever port you're running on

当我在嵌入式页面中使用此解决方案时,此解决方案仍会引发错误,该错误会从react应用程序中获取bundle.js.我认为,因为它将标头重写为localhost,所以在嵌入时,它正在寻找的localhost是该应用程序不再运行的地方

this solution still raises an error when I use this in an embedded page, that pulls the bundle.js from the react app. I think since it rewrites the header to localhost, when this is embedded, it's looking to localhost, which the app is no longer running on

这篇关于ngrok尝试连接到React开发服务器时无效的主机头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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