How to allow access outside localhost

后端 未结 15 855
失恋的感觉
失恋的感觉 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:17

    No package.json is necessery to change.

    For me it works using:

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

    Host: http://localhost:5999/

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

    A quick solution that might help someone :

    Add this line as value for start ng serve --host 0.0.0.0 --disable-host-check in your package.json

    ex:

    {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --disable-host-check",
    "build": "ng build",
    }
    

    And then simply do start or npm run start

    you will be able to access your project from other local IPs.

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

    If you facing same problem inside Docker, then you can use below CMD in Dockerfile.

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

    Or complete Dockerfile

    FROM node:alpine
    WORKDIR app
    RUN npm install -g @angular/cli
    COPY . .
    CMD ["ng", "serve", "--host", "0.0.0.0"]
    
    0 讨论(0)
提交回复
热议问题