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

Access outside localhost

Open ShadowManu opened this issue 10 years ago • 37 comments

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Linux Ubuntu 16.04 LTS
  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.11-webpack.2 (actually latest master at the time of this issue)
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. None in particular
  4. The log given by the failure. Normally this include a stack trace and some more information.
  5. Mention any other details that might be useful. Is there a way to access the app from ng serve (either dev or prod variants) from another LAN device? Thanks.

Thanks! We'll be in touch soon.

ShadowManu avatar Aug 22 '16 01:08 ShadowManu

It wasn't working for me. Doesn't look like a local port/firewall issue since npm's http-server runs ok.

ShadowManu avatar Aug 22 '16 08:08 ShadowManu

Related to this PR: https://github.com/angular/angular-cli/pull/1475#issuecomment-235986121 That comment will show you how to access the server on other devices: ng serve --host 0.0.0.0

intellix avatar Aug 22 '16 08:08 intellix

I do this on each new CLI project, to make ng serve listed on all interfaces every time:

echo '{ "host": "0.0.0.0"}' >.ember-cli

kylecordes avatar Aug 22 '16 11:08 kylecordes

@intellix I was thinking it was something about defining the listening interfaces. Thanks, exactly what I need and the original issue can be considered closed.

@kylecordes Even when angular-cli is based on ember-cli, can this (API) configuration be considered stable in the mid/long term?

ShadowManu avatar Aug 22 '16 15:08 ShadowManu

Closed as the original issue is resolved.

I would not rely on long term support for .ember-cli, no. Not even sure it'll work on the latest webpack version since we replaced the dev server.

filipesilva avatar Aug 23 '16 15:08 filipesilva

For this that found this on Google, the best way to do this is to edit your package.json file and edit "start" and replace "ng serve" with @intellix amazing solution "ng serve --host 0.0.0.0". Then just start with "npm start". npm start will always be here ;D

dylanh724 avatar Dec 28 '16 13:12 dylanh724

I still can't access it even when running on 0.0.0.0 :| 

chrillewoodz avatar Jan 31 '17 08:01 chrillewoodz

@chrillewoodz remember the --host part. It does work. It if doesn't its not on angular-cli part, check other suspects (routing, firewall, blah blah).

ShadowManu avatar Jan 31 '17 12:01 ShadowManu

@ShadowManu it doesn't work for me too. I set up the config correctly, but I can't reach the address (host unreachable) from any of the devices in the same LAN!

Screenshot

toioski avatar Jan 31 '17 13:01 toioski

@toioski I (and many more) can help out on the gitter channel, so we don't dirty up the thread.

ShadowManu avatar Jan 31 '17 14:01 ShadowManu

First verify your machine IP Address. On Windows, type ipconfig in Prompt (copy IPv4). On Mac, type ifconfig |grep inet in Terminal (copy inet).

In my case this is 192.168.0.10. Next, type ng serve --host 192.168.0.10. Ok, your app on air for all devices on same network.

Now only http://192.168.0.10:4200/ will work, localhost not more.

osvaldo-github avatar Feb 02 '17 13:02 osvaldo-github

@osvaldo-github only for complementing your answer is possible to change your hostname looks like a DNS

Windows

  1. Open with you favorite editor C:\Windows\System32\Drivers\Etc\hosts
  2. Edit your hosts name: 192.168.33.10 dev (Your IP and hostname what you want)
  3. To port 3000 access by your browser dev:3000

Linux

  1. Open with you favorite editor /etc/hosts
  2. Follow the step 2. and 3. off windows 👍

valterbarros avatar Feb 03 '17 13:02 valterbarros

Since angular cli uses webpack-dev-server, using this ng serve --host 0.0.0.0 will pass the --host option to the webpack dev server. is this correct?

ahmed-musallam avatar Mar 29 '17 19:03 ahmed-musallam

I have tried all of the above but none of them worked. Anybody who has a proper solution other than above please comment and post an issue to the angular-cli community.

** I guess, we are running dev environment (webpack-dev-server) using ng serve which logically should not be accessible to anyone else while in dev.

May help: https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a

shinde-prasad avatar Aug 20 '17 07:08 shinde-prasad

@shinde-prasad The issue might be an antivirus or a firewall that blocks access to the intended port. Have you tried with any other http server? lite-server? or http-server?

you can use any http server you prefer by following this wiki story

ahmed-musallam avatar Aug 21 '17 21:08 ahmed-musallam

Yes you're right. but if there is problem with webpack then what js use of it.

next problem I am facing is on my remote server machine I am not able to compile and run my code (angular-cli) with web pack.

shinde-prasad avatar Aug 24 '17 05:08 shinde-prasad

Please see https://github.com/angular/angular-cli/pull/6173 for for updates to this functionality as dictated by https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a.

filipesilva avatar Aug 31 '17 15:08 filipesilva

anyone resolved this issue ? we are getting the same error with new webpack - https://github.com/AngularClass/angular-starter#deployment

randeepnathtr avatar Oct 27 '17 11:10 randeepnathtr

I have resolved the issue by adding my ip address as host in ng serve .Since then , all colleagues in my company can access the application using port. example : I have an application running in 4200, can access the app in this way , 100.168.5.135:4200

"start": "ng serve --sourcemap false --host=100.168.5.135",

AhammadAliPK avatar Jan 16 '18 10:01 AhammadAliPK

FWIW, running ng serve --host MY_IP helped me accessing my Angular app from within a VirtualBox Windows machine for testing on IE, where all other solutions I had found on the internet had failed

igghera avatar Mar 17 '18 14:03 igghera