@@ -2,6 +2,29 @@ import { Server } from "../../server/server"
22import { UI } from "../ui"
33import { cmd } from "./cmd"
44import open from "open"
5+ import { networkInterfaces } from "os"
6+
7+ function getNetworkIPs ( ) {
8+ const nets = networkInterfaces ( )
9+ const results : string [ ] = [ ]
10+
11+ for ( const name of Object . keys ( nets ) ) {
12+ const net = nets [ name ]
13+ if ( ! net ) continue
14+
15+ for ( const netInfo of net ) {
16+ // Skip internal and non-IPv4 addresses
17+ if ( netInfo . internal || netInfo . family !== "IPv4" ) continue
18+
19+ // Skip Docker bridge networks (typically 172.x.x.x)
20+ if ( netInfo . address . startsWith ( "172." ) ) continue
21+
22+ results . push ( netInfo . address )
23+ }
24+ }
25+
26+ return results
27+ }
528
629export const WebCommand = cmd ( {
730 command : "web" ,
@@ -29,12 +52,36 @@ export const WebCommand = cmd({
2952 UI . empty ( )
3053 UI . println ( UI . logo ( " " ) )
3154 UI . empty ( )
32- UI . println (
33- UI . Style . TEXT_INFO_BOLD + " Web interface: " ,
34- UI . Style . TEXT_NORMAL ,
35- server . url . toString ( ) ,
36- )
37- open ( server . url . toString ( ) ) . catch ( ( ) => { } )
55+
56+ if ( hostname === "0.0.0.0" ) {
57+ // Show localhost for local access
58+ const localhostUrl = `http://localhost:${ server . port } `
59+ UI . println (
60+ UI . Style . TEXT_INFO_BOLD + " Local access: " ,
61+ UI . Style . TEXT_NORMAL ,
62+ localhostUrl ,
63+ )
64+
65+ // Show network IPs for remote access
66+ const networkIPs = getNetworkIPs ( )
67+ if ( networkIPs . length > 0 ) {
68+ for ( const ip of networkIPs ) {
69+ UI . println (
70+ UI . Style . TEXT_INFO_BOLD + " Network access: " ,
71+ UI . Style . TEXT_NORMAL ,
72+ `http://${ ip } :${ server . port } ` ,
73+ )
74+ }
75+ }
76+
77+ // Open localhost in browser
78+ open ( localhostUrl . toString ( ) ) . catch ( ( ) => { } )
79+ } else {
80+ const displayUrl = server . url . toString ( )
81+ UI . println ( UI . Style . TEXT_INFO_BOLD + " Web interface: " , UI . Style . TEXT_NORMAL , displayUrl )
82+ open ( displayUrl ) . catch ( ( ) => { } )
83+ }
84+
3885 await new Promise ( ( ) => { } )
3986 await server . stop ( )
4087 } ,
0 commit comments