2

I am getting invalid host header problem while i am trying to server my application by ng serve --host 0.0.0.0 . I have tried the following. 1.install -g angular-cli 2. cd to that app-directory 3. change port in angular-cli.json

"defaults": {
    "styleExt": "css",
    "component": {},
    "serve": {
              "port": 1337
             }
  }
  1. ng serve --host 0.0.0.0
  2. Requested url in browser is http://port-1337.angular2-jobproject0889272.codeanyapp.com/

    screen shot of container and browser

Pritam Parua
  • 672
  • 2
  • 8
  • 27

2 Answers2

3

I was looking to sovle a different problem and came across an answer that may work for you.

ng serve --port 8080 --host 0.0.0.0 --disableHostCheck true

Angular-cli GitHub

  • 1
    Could you be a little more verbose about why you think this is the solution and what is behind the link you provided ? – jadsq Dec 01 '17 at 17:57
0

If I'm understanding your question correctly, your issue could be stemming from Webpack's security impl.
As the Angular CLI uses Webpack by default to bundle your app, you have to abide by its requirements when using "ng serve". App bundles produced by Webpack now require the Host header of the request to match the listening address OR the host provided in the public option.

The public option is a --public flag passed with the "ng serve" command. On CodeAnywhere you should most likely care to indicate a port # as well. A valid "ng serve" command could look like this: $ ng serve --host 0.0.0.0 --port 3000 --public myproject-myusername.codeanyapp.com

(For HTTPS service, CodeAnywhere requires you use port 3000)

You can find your specific value for the --public flag in your CodeAnywhere IDE by right-clicking on your project's tree view Connection icon and selecting the "info" option.

To simplify things, you can set this up in your package.json file and then start the Angular server with the command: $ npm start

For example, you can modify the "start" element of the package.json "scripts" entry as follows: "scripts": { "ng": "ng", "start": "ng serve --host 0.0.0.0 --port 3000 --public myproject-myusername.codeanyapp.com" }

Hopefully this info is applicable to the issue you are facing. Good Luck!

AlohaCode
  • 764
  • 6
  • 4
  • The correct start command is: `ng serve --host 0.0.0.0 --port 3000 --public-host myproject-myusername.codeanyapp.com` – Marius Feb 10 '19 at 10:01