How to allow access outside localhost

后端 未结 15 838
失恋的感觉
失恋的感觉 2020-12-07 07:25

How can I allow access outside the localhost at Angular2? I can navigate at localhost:3030/panel easily but I can not navigate when I write my IP such as

相关标签:
15条回答
  • 2020-12-07 08:12

    I just edit angular.json file in my project as below and it works

    ...

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

    ...

    0 讨论(0)
  • For the people who are using node project manager, also this line adding to package.json will be enough. For angular CLI users, mast3rd3mon's answer is true.

    You can add

    "server": "webpack-dev-server --inline --progress --host 0.0.0.0 --port 3000"
    

    to package.json

    0 讨论(0)
  • 2020-12-07 08:13

    you can also introspect all HTTP traffic running over your tunnels using ngrok , then you can expose using ngrok http --host-header=rewrite 4200

    0 讨论(0)
  • 2020-12-07 08:13

    For the problem was Firewall. If you are on Windows, make sure node is allowed through

    0 讨论(0)
  • 2020-12-07 08:16

    Using ng serve --host 0.0.0.0 will allow you to connect to the ng serve using your ip instead of localhost.

    EDIT

    In newer versions of the cli, you have to provide your local ip address instead

    EDIT 2

    In newer versions of the cli (I think v5 and up) you can use 0.0.0.0 as the ip again to host it for anyone on your network to talk to.

    0 讨论(0)
  • 2020-12-07 08:16

    run command

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

    this will disable host check and allow to access from outside(instead of localhost) with IP address

    0 讨论(0)
提交回复
热议问题