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

ng serve method ip not open in another machines

Open sivaprabug opened this issue 10 years ago • 26 comments

OS?

Windows 8

Versions.

Could not start watchman; falling back to NodeWatcher for file system events. Visit http://ember-cli.com/user-guide/#watchman for more info. angular-cli: 1.0.0-beta.16 node: 6.6.0 os: linux ia32

After instal angular-cli for below step

npm install -g angular-cli

ng new PROJECT_NAME

cd PROJECT_NAME

After given below command

ng serve

http://localhost:4200 and http://127.0.0.1:4200 is working on same machine only if i open that machine ip with other machine means not opening. How to open the webpage in another machines, like that machine ip is 10.88.186.126 means how to open this url http://10.88.186.126:4200 in other machines browsers in the N/W.

sivaprabug avatar Oct 06 '16 05:10 sivaprabug

The solution is simple. Just bind to the correct interface address via ng serve --host=0.0.0.0

schnz avatar Oct 06 '16 08:10 schnz

@Coksnuss ,

Hi thanks for your reply any possible way to set in file for default ip for run time

sivaprabug avatar Oct 06 '16 09:10 sivaprabug

@Coksnuss ,

Is building this method but not running in browser

ng serve --host 10.0.136.126

sivaprabug avatar Oct 06 '16 09:10 sivaprabug

Not sure about the run-time setting. Regarding the binding: Bind to 0.0.0.0 (literally).

schnz avatar Oct 06 '16 09:10 schnz

Looks like the default host address cannot be set in any other way. The default setting (localhost) is hardcoded (https://github.com/angular/angular-cli/blob/master/packages/angular-cli/commands/serve.ts#L41) and ember CLI seems not to provide an alternative way to specify arguments (other than by passing it as argument switch) (https://ember-cli.com/api/files/lib_models_command.js.html)

However, you may set the PORT environment variable to override the default port 4200

schnz avatar Oct 06 '16 09:10 schnz

Oh ok we can given manual at build time only correct.

sivaprabug avatar Oct 06 '16 09:10 sivaprabug

10.0.136.126 is private ip, use the public ip ;)

fedemzcor avatar Nov 06 '16 05:11 fedemzcor

@fedecordova private that one is ok how can i access in other machines that is a issue :+1:

sivaprabug avatar Nov 06 '16 05:11 sivaprabug

use a digitalocean droplet, like ubuntu

fedemzcor avatar Nov 06 '16 05:11 fedemzcor

using following in the package.json makes it accessible to the host machine ng serve --host 0.0.0.0

pradhyu avatar Mar 23 '17 17:03 pradhyu

In case you get Invalid Host header, use ng serve --host=0.0.0.0 --disable-host-check

Tobiaqs avatar Jul 19 '17 11:07 Tobiaqs

The option '--disable-host-check' is not registered with the serve command. Run ng serve --help for a list of supported options.

I got it working by actually putting my local ip in the host.

ng serve --host=yourLocalIPHere

Hope this helps. :)

abhishekdgeek avatar Sep 25 '17 04:09 abhishekdgeek

@Coksnuss thank you, I write these lines in the .angular-cli.json file "defaults": { "serve": { "host": "0.0.0.0", "port": 4201 }, image

image

All fine now XD

LordAlastair avatar Nov 07 '17 13:11 LordAlastair

@LordAlastair Thanks for pointing that out! Very helpful

schnz avatar Nov 07 '17 16:11 schnz

@abhishekdgeek thank you, this problem drove me crazy I put my local ip and it finally worked

ammaralsayed avatar Mar 13 '18 09:03 ammaralsayed

If you want to save the effort of adding the --host flag everytime you run your app just add an entry to the 'defaults' prop in the angular-cli.json file like shown below:

angular-cli.json

{

  // ..... 

  "defaults": {
    "styleExt": "css",
    "component": {},
    "serve": {
      "host": "0.0.0.0",
      "port": 9876
    }
}

jqp5000 avatar Mar 24 '18 13:03 jqp5000

@LordAlastair @gsivaprabu @Coksnuss thank you, very helpful !!!

aswinkumarrhex avatar Apr 11 '18 12:04 aswinkumarrhex

In Dockerfile:

CMD ["ng", "serve", " --host 0.0.0.0", "--port 4201"]
frontend_1   | The option '--port 4201' is not registered with the serve command. Run `ng serve --help` for a list of supported options.
frontend_1   | ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Same goes for host is port parameter is not used.

holms avatar Apr 23 '18 01:04 holms

CMD ["ng", "serve", " --host 0.0.0.0", "--port 4201"]

Should be CMD ["ng", "serve", " --host", "0.0.0.0", "--port", "4201"]

Or even better ENTRYPOINT ["ng", "serve"] CMD [" --host", "0.0.0.0", "--port", "4201"]

schnz avatar Apr 23 '18 08:04 schnz

run angular with command - ng serve --host=0.0.0.0 --disable-host-check this will disable host check and allow to access with IPAddress

pallapraveen avatar May 09 '18 17:05 pallapraveen