(port: number, token?: string)
| 11 | |
| 12 | /** This machine's non-internal IPv4 addresses → shareable LAN URLs (same network only). */ |
| 13 | export function lanUrls(port: number, token?: string): string[] { |
| 14 | const suffix = token ? `?k=${token}` : ''; |
| 15 | const out: string[] = []; |
| 16 | for (const addrs of Object.values(os.networkInterfaces())) { |
| 17 | for (const a of addrs ?? []) { |
| 18 | // Node 18+ reports family as 'IPv4' (string); older as 4 (number) — accept both. |
| 19 | if ((a.family === 'IPv4' || (a.family as unknown) === 4) && !a.internal) { |
| 20 | out.push(`http://${a.address}:${port}/${suffix}`); |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | return out; |
| 25 | } |
| 26 | |
| 27 | /** Pull the public https URL out of a cloudflared/ngrok log line. Pure → unit-testable. */ |
| 28 | export function parseTunnelUrl(text: string): string | undefined { |
no test coverage detected