Ionic 4 angular - Invalid Host header error

ionic
angular

#1

Hi, I am trying to run ionic 4 angular app, but can’t solve the Invalid Host header error. I have encountered this problem only on c9 and presume it’s because of the cloud infrastructure.

Here is the public c9 repo: https://c9.io/wixosk/ionic4publictest

I have tried to disable host check:

ionic serve --host $IP --port $PORT --public $C9_HOSTNAME --history-api-fallback --disableHostCheck --disable-host-check

or using specific public host:

ionic serve -p 8080 -H 0.0.0.0 --public-host [url]

But none of that (or combination) seems to work :cry:
Can you please point me into right direction?
Thank you very much!


#2

I disabled the host check in the file:
/node_modules/webpack-dev-server/lib/Server.js

method:
Server.prototype.checkHost = function (headers) { (currently it’s line 617)
I added return true; as the first line in this method.


#3

Thank you @phptechs! It’s working now. :clap:

I am just wondering if version update of webpack would not override the change? Isn’t there some kind of permanent solution, flag or settings?

But thanks for this solution. It certainly did the trick :wink:


#4

Unfortunately, I don’t know about the flags, the one that should work (disableHostCheck) seems to be not working for me.

So for now I’m gonna use this command from the project’s directory (in case webpack got updated or something): :wink:

sed -i -r 's/(Server\.prototype\.checkHost.*)/\1\nreturn true;/' ./node_modules/webpack-dev-server/lib/Server.js


#5

ionic serve -- --disable-host-check babe, you forgot this -- it pass to internal command