Skip to content

Commit 48d7b9b

Browse files
committed
terminal: also print actual listening addr in startup info
Fixes #214 by printing the actual listening host:port as well as the browser connection string.
1 parent e6fe83f commit 48d7b9b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

terminal.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,11 @@ func (g *LightningTerminal) showStartupInfo() error {
747747
}
748748

749749
// If there's an additional HTTP listener, list it as well.
750+
listenAddr := g.cfg.HTTPSListen
750751
if g.cfg.HTTPListen != "" {
751-
host := strings.ReplaceAll(
752-
strings.ReplaceAll(
753-
g.cfg.HTTPListen, "0.0.0.0", "localhost",
754-
), "[::]", "localhost",
755-
)
756-
info.webURI = fmt.Sprintf("%s, http://%s", info.webURI, host)
752+
host := toLocalAddress(listenAddr)
753+
info.webURI = fmt.Sprintf("%s or http://%s", info.webURI, host)
754+
listenAddr = fmt.Sprintf("%s, %s", listenAddr, g.cfg.HTTPListen)
757755
}
758756

759757
str := "" +
@@ -764,10 +762,10 @@ func (g *LightningTerminal) showStartupInfo() error {
764762
" Node status %s \n" +
765763
" Alias %s \n" +
766764
" Version %s \n" +
767-
" Web interface %s \n" +
765+
" Web interface %s (open %s in your browser) \n" +
768766
"----------------------------------------------------------\n"
769767
fmt.Printf(str, info.mode, info.status, info.alias, info.version,
770-
info.webURI)
768+
listenAddr, info.webURI)
771769

772770
return nil
773771
}
@@ -790,3 +788,10 @@ func (i *ClientRouteWrapper) Open(name string) (http.File, error) {
790788

791789
return i.assets.Open("/index.html")
792790
}
791+
792+
// toLocalAddress converts an address that is meant as a wildcard listening
793+
// address ("0.0.0.0" or "[::]") into an address that can be dialed (localhost).
794+
func toLocalAddress(listenerAddress string) string {
795+
addr := strings.ReplaceAll(listenerAddress, "0.0.0.0", "localhost")
796+
return strings.ReplaceAll(addr, "[::]", "localhost")
797+
}

0 commit comments

Comments
 (0)