Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix "invalid host header" in Angular

Tags:

url

angular

hosts

I have an app in Angular v4 which have to change the scss dependong of the url of access. For example: if link in the browser is "example.com" then the app have background-color: black if the link is"example2.com" then the background-color: red

I have the next problem:

when I go to the hosts in C:\Windows\System32\drivers\etc and I set the next configuration in hosts 127.0.0.1 example.com 127.0.0.1 example2.com

then I run the app with "example.com:4200" the app doesn't run... the browser show me this message

"invalid host header"

How do I fix this problem?

like image 934
Sergio Mendez Avatar asked Sep 06 '18 22:09

Sergio Mendez


1 Answers

This appeared for me under angular 7.2.1

Assuming you're using the Angular CLI, the solution was to add the following line in angular.json under architect>serve>options:

"disableHostCheck": true
like image 166
Fredrik_Borgstrom Avatar answered Sep 19 '22 23:09

Fredrik_Borgstrom