HiveBrain v1.2.0
Get Started
← Back to all entries
patternreactCritical

Invalid Host Header when ngrok tries to connect to React dev server

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
ngrokwhendevconnecttriesreactinvalidserverhostheader

Problem

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


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

Solution

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


obviously, replace 8080 with whatever port you're running on

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

Code Snippets

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

Context

Stack Overflow Q#45425721, score: 1041

Revisions (0)

No revisions yet.