create-react-app: Can't remote develop create-react-app due to "Invalid Host Header"
At work I do all my development shelled into an AWS instance. This means my code and dev server are both remote, but my browser is local. When I try to access my react app, I get “Invalid Host Header”. I think this is due to the fix for webpack/webpack-dev-server#887. From googling around, it looks like I can fix this by ejecting, but that’s supposed to be for power users and the reason I’m trying create-react-app in the first place is I don’t understand anything about the ecoystem yet.
Is there anything I can do about this aside from ejecting? Is this worth fixing somehow?
Someone asked a question about this on Stack Overflow but didn’t get a response.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 30 (9 by maintainers)
Can you put your HOST into
.envfile?Then restart the development server.
Please update to
react-scripts@1.0.2.It fixes this issue for users who don’t use the
proxyfeature.If you do use the
proxyfeature, please follow these instructions.Having the same issue, particularly when trying to work with c9.io
edit: Solved it by adding
0.0.0.0 <domain>in my/etc/hostsin addition to adding the domain to the.envfile. Also, as a reference, we might want to inject thepublicoption somewhere in case for whatever reason we want to serve the dev env to a public domain (thinking for example live coding).I use a VM to develop my app, so my machine maps the VM’s IP address to the domain I’m using, for this case my
/etc/hostsis doing this:My API is on a remote server under SSL and uses the same domain:
https://stabe.be/api/...I tried configuring the
proxyfeature by adding"proxy": "https://stabe.be/api"topackage.json, but I get a 404 error every time:If I try to the application using
HTTPS=trueandDANGEROUSLY_DISABLE_HOST_CHECK=trueand call the API directly (without theproxyfeature) I got this error instead:And if I don’t use the
proxyand don’t run the application on development under HTTPS, the first load works fine but if I reload the application the browser redirects it to use only thehttpsprotocol, and this returns a 404 request.This is my
.envfile:@gaearon do you have any suggestion here?
Thanks in advance!
@gaearon It works after updating to 1.0.2. Thanks a bunch.
I’ve tried everything that is written in the docs, and the only config that is working is
DANGEROUSLY_DISABLE_HOST_CHECK😞Since I’ve already spent a few days trying to work this out for now I have to move on… When I’ll have some spare time I’ll try to dig deeper into why the error is happening and I’ll post here the results
This is the exact security flaw this change was meant to close. An outbound (non internal) IP should never be able to connect to a development server.
Changing theHOSTisn’t what would make this work, we’d need to add an explicitallowedHostsoption topackage.jsonwhich listed his public IP.