Search code examples
polymer

How to make polymer serve be accessible on the internet or Lan, instead localhost?


I have a Polymer 2 component that I serve locally running

polymer serve

I get the following back:

Files in this directory are available under the following URLs
applications: http://127.0.0.1:8081
reusable components: http://127.0.0.1:8081/components/component-name/

That works very well; as expected I am able to open a local URL and view the component on Chrome.

I need to test this component on an Android Device, the best way it would be (please correct me if I´m wrong) to make this polymer component available on the internet or my local network.

Any suggestion is appreciated. thanks.


Solution

  • When you use the serve command you have some additional parameters. With one of them (-H) you can set the IP you want to be used. So instead of launching the server for your loopback (localhost) IP (the default), you can use your LAN IP (I guess most likely something like 192.169.x.x), or even:

    polymer serve -H 0.0.0.0
    

    "0.0.0.0" basically meaning "all IPv4 addresses on the local machine". So now you only need to know your IP in the network you are and that Android device is connected also. So if both of them are connected to the same router you should be able to open in your phone an URL like http://192.168.x.x:8081