angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Invalid Host header after updating to 1.0.1

Open SanderElias opened this issue 9 years ago • 49 comments

- [x ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

1.0.1

Repro steps.

update to 1.0.1 ng serve browser will read: Invalid Host header, and do nothing

The log given by the failure.

none

Desired functionality.

serve my application.

Mention any other details that might be useful.

Downgrading to 1.0.0 fixed the issue. (BTW, running on ubuntu and debian, same issue)

SanderElias avatar Apr 25 '17 05:04 SanderElias

Even using ng serve --host 0.0.0.0 dosnt work anymore :(

niklas-dahl avatar Apr 28 '17 14:04 niklas-dahl

It's working with - - host 0.0.0.0. What's your use case?

vivekamin avatar Apr 28 '17 16:04 vivekamin

That doesn't work. At least behind a proxy.

dinvlad avatar Apr 28 '17 16:04 dinvlad

Having same problem within my dev env. I run my IDE on linux VM, and then access to that from my windows machine. With 1.0.0 angular-cli this could be solved just by using host 0.0.0.0, but now this won't work :(

It would be nice if there was a simple option for ng serve to make this work just like previously.

tarlepp avatar Apr 28 '17 17:04 tarlepp

imho changing code under node_modules is the worst solution for this...

tarlepp avatar Apr 30 '17 14:04 tarlepp

I checked the version of webpack I used and already have the fix at line 402. However angular app still does not work in current verison of cloud9 ide.

Below is my package.json

{
  "name": "mean-app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.0.1",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}

kktam avatar Apr 30 '17 22:04 kktam

@kktam, my current workaround is to add 0.0.0.0 <workspace>-<username>.c9users.io to /etc/hosts file, and to run ng serve -H <workspace>-<username>.c9users.io to serve the app.

dinvlad avatar May 01 '17 03:05 dinvlad

ng serve --host 0.0.0.0 -ssl -p 3000 stopped working after CLI update to 1.0.1

I use CentOS 6

RomaDotDev avatar May 01 '17 16:05 RomaDotDev

I'm not quite sure what this is and I can't seem to find any documentation anywhere. Can anyone provide a link or perhaps an explanation to why this was implemented?

P.S. using the disableHostCheck: true option in my webpack.config.js solved the issue for me.

elliotwesoff avatar May 03 '17 08:05 elliotwesoff

@elliotwesoff There are some links in this thread, but this blogpost explains it the best in my opinion.

This is activity caused by a webpack security fix, and not by the CLI, I reopened the issue because the missing cmd-line switches that are needed to work around this, are not exported by ng serve.

SanderElias avatar May 03 '17 09:05 SanderElias

Hey all, thanks for all the information added about this issue. The blogpost @SanderElias posted in https://github.com/angular/angular-cli/issues/6070#issuecomment-298861063 covers it pretty well.

I think the CLI will have to add the --public flag as well to fix this case.

filipesilva avatar May 03 '17 09:05 filipesilva

The best solution available right now for users affected by this problem is to downgrade to 1.0.0.

filipesilva avatar May 03 '17 09:05 filipesilva

Actually, now that I'm re-reading all the comments again, @amiram and @flackjap suggest using the existing --host flag (e.g. ng serve --host app.myapp.com).

If a current flag is enough, there's no need to add a new one. If this doesn't work for some setups please let me know.

filipesilva avatar May 03 '17 10:05 filipesilva

If you're using the ---host parameter to Angular-CLI, you obviously want the test server to serve on that address (possibly 0.0.0.0). It seems redundant to have to give additional parameters for that, even if it internally means that Angular-CLI needs to push extra parameters to the webpack dev server.

wulfsberg avatar May 03 '17 10:05 wulfsberg

If you mean that an existence of --host will configure webpack to ignore the host header, then it is fine. It's not convenient to edit the command each time and write the ip address. The command is in package.json so it is common for all the team but each has a different address for the web server.

amiram avatar May 03 '17 10:05 amiram

@filipesilva I upgraded another project to give this an another spin. Here are the results:

1 --host 0.0.0.0 always ends in invalid host header 2 --host <public ip> works as long as the client connects using the same ip-number, using a hostname doesn't work 3 --host <name> works as long as the client connects using the same name. This might need changing the OS host files, or your local DNS server setup.

So, the problem is mostly the --host 0.0.0.0. When the --public switch is added, you can add a name, without changing anything in your system's settings. I think this is preferable over my 3rth option.

Without the --public, it needs the disableHostCheck which might be a security issue, so this should not be enabled without an explicit setting and/or a warning.

SanderElias avatar May 03 '17 12:05 SanderElias

@flackjap Adding return true to checkHost does work for me, bu return an error : Could not connect to REST server. Please check your configuration details

rahianeja avatar Aug 21 '17 06:08 rahianeja

@rahianeja This issue has been solved and closed. https://github.com/angular/angular-cli/pull/6173 Why don't you just use --disable-host-check ?

If you still have to use the older version, then change the disableHostCheck to false, in webpackDevServer config file.

flackjap avatar Aug 22 '17 12:08 flackjap

solution for me in cloud9: open node_modules/webpack-dev-server/lib server.js edit line 451 change false to true edit line 473 change false to true this allows "public host name" of listening address and the allowedHost === hostname
must accept that public hostname and allowedHost are exactly ===

jrohatiner avatar Aug 24 '17 22:08 jrohatiner

@jrohatiner no need for that, I use mine in Cloud9 too without any modifications to the source code. Just use --public-host parameter.

dinvlad avatar Aug 25 '17 02:08 dinvlad