Skip to content

feat(cli): name the interfaces behind a wildcard bind - #1376

Open
gzliudan wants to merge 1 commit into
agegr:mainfrom
gzliudan:feat/cli-reachable-addresses
Open

gzliudan wants to merge 1 commit into
agegr:mainfrom
gzliudan:feat/cli-reachable-addresses

Conversation

@gzliudan

Copy link
Copy Markdown

Problem

pi-web -H 0.0.0.0 prints

- Network:       http://0.0.0.0:30141

as the only startup URL meant for another machine, and no machine can open it. bin/pi-web.js always forwards the bind address to Next (nextArgs.push("-H", hostname)), and Next's start-server only looks at the host's interfaces when -H is absent:

const networkHostname =
  hostname ?? getNetworkHost(isIPv6(actualHostname) ? 'IPv6' : 'IPv4')

So with a wildcard bind the banner repeats the flag value. pi-web itself never calls os.networkInterfaces(), so nothing in the output names an interface or gives a reachable address — while the README recommends --hostname 0.0.0.0 for phone/LAN access.

Fixes #1375.

Change

  • bin/network-addresses.js (new): formatReachableAddresses(hostname, port) returns "" unless the hostname is 0.0.0.0, :: or [::]. Otherwise it lists every non-internal address of the bound family, skipping scoped IPv6 (a link-local address needs a zone id and cannot be pasted into another machine's browser), one line per interface, names padded to a single column:

    Reachable at:
      eth0   http://192.168.1.20:30141
      wlan0  http://10.0.0.7:30141
    

    Port 0 prints nothing, because the OS picks a port the launcher never learns.

  • bin/pi-web.js: prints that block once, on "Ready", after Next's banner. The bind address, the authentication warning and the loopback URL the browser opener uses are unchanged.

  • lib/network-addresses.test.mjs (new): wildcard detection, IPv4 and IPv6 enumeration, loopback/scoped filtering, alignment, and the two empty cases.

Verification

  • node --test lib/network-addresses.test.mjs lib/pi-web-options.test.mjs lib/pi-web-cli-commands.test.mjs: 39 pass.

  • npx eslint on the three changed files: clean.

  • npx tsc --noEmit: clean.

  • Real launcher on Linux (patch copied into a global install), pi-web -H 0.0.0.0 -p 30198 --no-open:

    Warning: pi-web is listening on 0.0.0.0 without authentication. Only use this on a trusted network.
    ▲ Next.js 16.3.8
    - Local:         http://localhost:30198
    - Network:       http://0.0.0.0:30198
    ✓ Ready in 75ms
    Reachable at:
      ens33  http://192.168.223.128:30198
    ✓ Running next.config.ts took 20ms
    

`next start -H 0.0.0.0` makes Next.js repeat the bind address in its own
"Network:" line, so the only startup URL printed is one that no other machine
can open. Next only enumerates the host's addresses when `-H` is absent, and
pi-web always passes it.

When the effective hostname is `0.0.0.0`, `::` or `[::]`, print one line per
non-internal interface of the bound family once the server is ready:

  Reachable at:
    eth0   http://192.168.1.20:30141

The bind address is unchanged, and the loopback URL the browser opener uses
stays as it was.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup output shows "Network: http://0.0.0.0:30141" instead of a real interface and IP

1 participant