ionic serve starts on localhost and not the server

2019-03-27 17:42发布

When running ionic serve I see this:

  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

Which means I cannot access the app from a browser as its only listening for localhost. How can I change localhost to the actual server IP?

Thanks

2条回答
Fickle 薄情
2楼-- · 2019-03-27 18:35
`ionic address`  

gives a list of address. select one

eg :

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:
查看更多
倾城 Initia
3楼-- · 2019-03-27 18:38

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

  • try --lab option to see multiple platforms at once.

    ionic serve --address localhost --lab

Clikc to Learn more options

OLd Answer:

Use -address localhost

run

ionic serve -address localhost

to test your apps on multiple screen sizes and platform types use with --lab

ionic serve --lab -address localhost
查看更多
登录 后发表回答