lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.22k stars 86 forks source link

Add option to display the URL as a QR code #148

Closed larryw3i closed 4 years ago

larryw3i commented 4 years ago

Maybe generating qrcode is been needed, it's convenient if get my laptop files just scan the qrcode

image

tiagostutz commented 4 years ago

Interesting... for development porpuses this could be really useful. This could be one of the "View options", right?

What do you think @75lb ?

75lb commented 4 years ago

yes, ws --qr would be a useful feature. 👍

Which URL should the QR encode? When you run ws, three URLs are printed: the hostname, local IP and one or more network interface IP addresses.

$ ws
Listening on http://mba4.local:8000, http://127.0.0.1:8000, http://192.168.0.200:8000

Which of these URLs should the QR represent? We need to pass in an argument which identifies which URL to display as QR.

$ ws --qr en0
<print QR code for network interface with name 'en0'>

Please implement in lws. You'll need to update the built-in cli-view.

  1. Clone the latest lws code.
  2. Add a list-network-interfaces option here. Make it a boolean flag. OptionDefinition objects are documented here.
  3. At this point, if config.listNetworkInterfaces is set, print value (the address list) to the console so the user can see the network interface names.
  4. Next, add a qr option definition here with type String. The value passed to --vr should be an interface name (the user will first run ws --list-network-interfaces to see the interface names).
  5. At this point, check if config.vr is set. If so, search value (an array of objects) for the object with a name matching the supplied config.vr value. Print a QR code for this object's url value.
tiagostutz commented 4 years ago

Nice! I'm going to work on this.

If the user does not pass any argument we could print by default the URL that matches one of the IETF private address because that's probably the address the user is looking for when scanning with an external device that is in the same private (wi-fi) network. Right?

75lb commented 4 years ago

Yes, that sounds like a sensible default - using a mobile device on the same LAN is a common use case.

Would that default also work when both your laptop and mobile device are connected to a mobile network? Would be a bonus if so.

tiagostutz commented 4 years ago

Like the laptop using the mobile as a hotspot, right? If so, it would work.

tiagostutz commented 4 years ago

@larryw3i this issue is being built and discussed here https://github.com/lwsjs/lws/issues/13

75lb commented 4 years ago

Released in v4.1.0. Cheers! 👍