Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access outside localhost #1793

Closed
ShadowManu opened this issue Aug 22, 2016 · 37 comments
Closed

Access outside localhost #1793

ShadowManu opened this issue Aug 22, 2016 · 37 comments

Comments

@ShadowManu
Copy link

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
Copy link
Author

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

@intellix
Copy link
Contributor

intellix commented Aug 22, 2016

Related to this PR: #1475 (comment)
That comment will show you how to access the server on other devices: ng serve --host 0.0.0.0

@kylecordes
Copy link

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

@ShadowManu
Copy link
Author

@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?

@filipesilva
Copy link
Contributor

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.

@dylanh724
Copy link

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

@chrillewoodz
Copy link

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

@ShadowManu
Copy link
Author

@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).

@toioski
Copy link

toioski commented Jan 31, 2017

@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

@ShadowManu
Copy link
Author

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

@osvaldo-github
Copy link

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.

@valterbarros
Copy link

@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 👍

@ahmed-musallam
Copy link

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?

@shinde-prasad
Copy link

shinde-prasad commented Aug 20, 2017

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

@ahmed-musallam
Copy link

@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

@shinde-prasad
Copy link

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.

@filipesilva
Copy link
Contributor

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

@randeepnathtr
Copy link

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

@AhammadAliPK
Copy link

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",

@igghera
Copy link

igghera commented Mar 17, 2018

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

@taurus227
Copy link

As of at least Angular CLI 1.0 you can set these directly in .angular-cli.json underneath the defaults element:

{
  "defaults": {
    "serve": {
      "port": 4444,
      "host": "0.0.0.0"
    }
  }
}

Source

@alberthendriks
Copy link

alberthendriks commented May 2, 2018

@taurus227 's solution is the ONLY one that worked for me. Remember to replace "0.0.0.0" host with your ip. ng-serve kept saying:

** NG Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200 **

or "localhost" in place of "0.0.0.0"

Now that it works, it says:

** NG Live Development Server is listening on 192.168.x.y:4200, open your browser on http://192.168.x.y:4200 **

@taurus227
Copy link

Actually for me it works with 0.0.0.0. That just means any IP address.

@porfidev
Copy link

porfidev commented May 8, 2018

without use ng-cli

npm run start -- --host=0.0.0.0 --port=4500

after first -- start all parameters for ng-cli as you need it.

@pallapraveen
Copy link

run the command

ng serve --host=0.0.0.0 --disable-host-check

to disable host check and access with IPAddress

@sotiris-rafail
Copy link

I wanted to ask about the new angular.json file which replaced the .angular-cli.json. I used to override the host value there, but now i can not find how to override it. Does anyone has run into the same problem? Can you suggest me a solution other than writing host as parameter?

@ScottFred
Copy link

@sotiris-rafail I think what you are looking for is "dev-server" which has the "host" option. It looks like "host" is not available in the "server" section of the angular.json.

References

@jyte
Copy link

jyte commented Aug 17, 2018

For anyone looking on how to solve that with the new angular.json file, adding the "host": "0.0.0.0" line at the right place works for me

        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "project:build",
            "host": "0.0.0.0"
          },

@ankushthakur12
Copy link

For mac:

  1. check the ip address of your machine with this command: ifconfig |grep inet
  2. copy the ip address.
  3. now type: ng serve --host

screen shot 2018-09-11 at 1 54 12 pm

@naveedkamran
Copy link

I have the same issue and using npm run ng serve --host 0.0.0.0 does not allow it to be accessed on network. Though app is still accessible locally.

@iampratapak
Copy link

ng serve --host 0.0.0.0 is a security risk isn't it? Angular cli giving warning. I don't think we can use this for production deployment

> ng serve --host 0.0.0.0

WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.

Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
WebSocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
** Angular Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **

and with --disableHostCheck

WARNING: Running a server with --disable-host-check is a security risk. See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a for more information.

@rovertzxd
Copy link

I have the same issue and using npm run ng serve --host 0.0.0.0 does not allow it to be accessed on network. Though app is still accessible locally.

@naveedkamran
if you are runing from npm you'll need to add two more hipens after ng serve.
Like this npm run ng serve -- --host=0.0.0.0

@juanmendes
Copy link

juanmendes commented Jun 13, 2019

@pratapgowda007 You shouldn't be using ng's dev server for production, not sure what you mean

@jkatnik
Copy link

jkatnik commented Aug 11, 2019

update to @jyte answer - solution for angular 7 changed to

{ "projects": {
    "foo-project": {
      "architect": {
        "serve": {
          "configurations": {
            "host": {
              "host": "0.0.0.0"
            }
          }}}}}}

@JeffreyXieCn
Copy link

update to @jyte answer - solution for angular 7 changed to

{ "projects": {
    "foo-project": {
      "architect": {
        "serve": {
          "configurations": {
            "host": {
              "host": "0.0.0.0"
            }
          }}}}}}

Doesn't work for me in Angular 8. But @jyte 's answer works for me in Angular 8.

@cnbalbin
Copy link

I follow all the possible solution from this page, and I can say I successfully accessed my application outside my localhost, but the problem is when I try to sign in, I cannot log in and I can't see what is the error. Is their any possible solution for this, might I missed something. by the way I am newbie here, hope you guys can support my query, thank you so much

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests