ionic serve在localhost而不是服务器IP上启动

lul*_*u88 8 cordova ionic-framework ionic

当运行离子服务时,我看到:

  Gulp startup tasks: [ 'sass', 'watch' ]
  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
Run Code Online (Sandbox Code Playgroud)

这意味着我无法从浏览器访问该应用程序,因为它只侦听localhost.如何将localhost更改为实际的服务器IP?

谢谢

Far*_*C K 20

Multiple addresses available.
Please select which address to use by entering its number from the list below:
 1) 10.0.0.9 (wlan0)
 2) 172.16.58.1 (vmnet1)
 3) 172.16.16.1 (vmnet8)
 4) localhost
Std in before prompt
Address Selection:
Run Code Online (Sandbox Code Playgroud)

给出一个地址列表.选择一个

例如:

Multiple addresses available.
Please select which address to use by entering its number from the list below:
 1) 10.0.0.9 (wlan0)
 2) 172.16.58.1 (vmnet1)
 3) 172.16.16.1 (vmnet8)
 4) localhost
Std in before prompt
Address Selection:
Run Code Online (Sandbox Code Playgroud)


Lah*_*hah 5

NEW ANSWER:

For the newer version of ionic this has been changed to --address

  • ionic address command give the option to select your IP address. And you can select one from.

  • You can explicitely define IP address and port like this:

    ionic serve --address address --port port //8100 is default

    example 1: ionic serve --address localhost --port 8101

    example 2: ionic serve --address localhost --port 8101

  • 尝试--lab选项可一次查看多个平台。

    ionic serve --address localhost --lab

单击以了解更多选项

OLd答案:

使用 -address localhost

ionic serve -address localhost
Run Code Online (Sandbox Code Playgroud)

在与--lab一起使用的多种屏幕尺寸和平台类型上测试您的应用

ionic serve --lab -address localhost
Run Code Online (Sandbox Code Playgroud)