使用离子服务时无法访问开发服务器

Can't access dev server when using ionic serve

我正在尝试使用 ionic serve 访问空白离子模板。它说它正在工作,但我只是在 Chrome 中得到 'page not found'。我非常有信心端口不是问题,因为我可以在 http://192.168.99.100:35729 and if I swap them, on http://192.168.99.100:8100.

上访问实时重新加载页面

nmap 告诉我:

PORT     STATE  SERVICE
8100/tcp closed xprint-server

我也在使用 Docker。 192.168.99.100 是我的虚拟机的 IP。

Adrians-iMac:kosher_app Adrian$ docker run -p 8100:8100 -p 35729:35729 -v /Users/Adrian/Documents/current_projects/kosher_app/kosher:/ionic -i -t app serve
    Running dev server: http://localhost:8100
    Running live reload server: http://localhost:35729
    Watching : [ 'www/**/*', '!www/lib/**/*' ]
    Ionic server commands, enter:
      restart or r to restart the client app from the root
      goto or g and a url to have the app navigate to the given url
      consolelogs or c to enable/disable console log output
      serverlogs or s to enable/disable server log output
      quit or q to shutdown the server and exit

如果有帮助,这是我的Docker文件:

FROM google/nodejs

WORKDIR /ionic
VOLUME ["/ionic"]
RUN npm install -g cordova ionic && ionic platform add android

EXPOSE 8100
EXPOSE 35729
ENTRYPOINT ["ionic"]
CMD ["serve"]

这是 docker port 应用于容器时的结果:

35729/tcp -> 0.0.0.0:35729 8100/tcp -> 0.0.0.0:8100

Ionic 当前有一个问题 listening/binding 到 0.0.0.0。这在新测试版中已修复。此线程中提到了一个解决方法:

来源:https://github.com/driftyco/ionic-cli/issues/322

我的解决方法是在我的 Dockerfile 中添加这一行:

RUN sed -i 's/localhost/0.0.0.0/' /usr/lib/node_modules/ionic/lib/ionic/serve.js

或者在某些情况下(取决于版本):

RUN sed -i 's/localhost/0.0.0.0/' /usr/lib/node_modules/ionic/lib/serve.js

尝试npx cap sync 有关更多信息,请参阅 https://capacitorjs.com/docs/basics/workflow#sync-your-project