"Invalid Host header" when running Angular/cli development server c9.io
126,478
Solution 1
The --disable-host-check
flag works fine if you need to run from Cloud9.
I use the following command:
ng serve --open --host $IP --port $PORT --disable-host-check
Solution 2
In angular.json, add the following under architect -> serve -> options
"disableHostCheck": true
Got the answer from this Github Issue Page
Solution 3
You need to specify the host
ng serve --port 8080 --host 123.34.56.78
Solution 4
This works for me :
ngrok http --host-header=rewrite PORT
for instance :
ngrok http --host-header=rewrite 4200
Solution 5
See this issue
Edit the following line in
node_modules/webpack-dev-server/lib/Server.js
(line 425), change to:return true;
I am using cloud9 IDE then run:
ng serve --port 8080 --host 0.0.0.0
. Now works fine.
Author by
Olejs
Updated on August 20, 2022Comments
-
Olejs over 1 year
Current command:
ng serve --host --public $IP:$PORT
Results on my website:
Invalid Host header
-
Teddy Markov almost 7 yearsThe above solution might work too but this is what I needed.
-
tarn almost 7 yearsYou can run without edit code by append --disableHostCheck true ng serve --host 0.0.0.0 --port 8080 --disableHostCheck true
-
rakesh kashyap over 6 yearschange the following line in node_modules/webpack-dev-server/lib/Server.js: if(this.disableHostCheck) return true; change to return true;
-
niaomingjian over 6 yearsIt works. But where can I find out the explanation about the '--public' option online? I only found out the '--public-host' option
-
Nitin . over 6 yearsng serve --port 8080 --publicHost 0.0.0.0
-
jmq over 6 yearsSee this Angular CLI GitHub issue regarding disableHostCheck's potential risks, just to be aware of what you're doing.
-
Matthew Dolman almost 6 yearsAdetiloye's answer is much better
-
Krishnadas PC almost 6 yearsIt will work but if you use
--disable-host-check
you will get a warning in the console.WARNING: Running a server with --disable-host-check is a security risk. See
medium.com/webpack/… for more information. -
Mathews Sunny over 5 yearsAdd some more description.
-
edi over 5 yearsthis option is not available anymore
-
Cel over 5 yearsthis worked for me, but it was necessary to include the exact subdomain used in the browser for public-host:
ng serve --host 0.0.0.0 --public-host sub.myhost.com
-
Vinay Pandya almost 5 yearsthis is worked for me ng serve --host 0.0.0.0 --disableHostCheck true. thank you @CookAtRice
-
Ubaid Azad almost 5 yearsRun
ng serve --host 0.0.0.0 --disable-host-check
-
Pablo W. almost 5 yearsyou should not be touching node vendors
-
Cec over 4 yearsmodifying node_modules instead of using proper ng-cli parameters is absurdly bad practice
-
Tom Doe about 4 yearsJust want to point out that this resolves the issue for running locally on the machine. I'm not sure if it solves it for Cloud9 per the OP original question above.
-
jowey about 4 yearsThis is the right an clean solution if you want to enable it on every
ng serve
(and probably you want to in development) -
LuizLoyola over 3 yearsNot the answer the OP needed, but thanks for adding it anyway. Works for ngrok tunneling without changing project settings.
-
danday74 over 3 yearsa better solution
-
JellicleCat about 3 yearsIs there a way to configure this for the development environment only?
-
ruwan800 about 3 years@JellicleCat Set
"disableHostCheck": false
under architect -> serve -> configurations -> production -
vanduc1102 about 2 yearsI am building a Shopify app, I have to run
yarn start frontend --public-host=abc-xyz.ngrok.io
, with this answer, i can justyarn start frontend
. I think the issue should be fixed withdisableHostCheck
.