Skip to content

Commit 2ebff9b

Browse files
committed
terminal: start additional HTTP listener
1 parent b23ae70 commit 2ebff9b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

terminal.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,28 @@ func (g *LightningTerminal) startMainWebServer() error {
592592
}
593593
}()
594594

595+
// We only enable an additional HTTP only listener if the user
596+
// explicitly sets a value.
597+
if g.cfg.HTTPListen != "" {
598+
insecureListener, err := net.Listen("tcp", g.cfg.HTTPListen)
599+
if err != nil {
600+
return fmt.Errorf("unable to listen on %v: %v",
601+
g.cfg.HTTPListen, err)
602+
}
603+
604+
g.wg.Add(1)
605+
go func() {
606+
defer g.wg.Done()
607+
608+
log.Infof("Listening for http on: %v",
609+
insecureListener.Addr())
610+
err := g.httpServer.Serve(insecureListener)
611+
if err != nil && err != http.ErrServerClosed {
612+
log.Errorf("http server error: %v", err)
613+
}
614+
}()
615+
}
616+
595617
return nil
596618
}
597619

@@ -611,8 +633,8 @@ func (g *LightningTerminal) showStartupInfo() error {
611633
version: build.Version(),
612634
webURI: fmt.Sprintf("https://%s", strings.ReplaceAll(
613635
strings.ReplaceAll(
614-
g.cfg.HTTPSListen, "0.0.0.0", "127.0.0.1",
615-
), "[::]", "[::1]",
636+
g.cfg.HTTPSListen, "0.0.0.0", "localhost",
637+
), "[::]", "localhost",
616638
)),
617639
}
618640

@@ -659,6 +681,16 @@ func (g *LightningTerminal) showStartupInfo() error {
659681
}
660682
}
661683

684+
// If there's an additional HTTP listener, list it as well.
685+
if g.cfg.HTTPListen != "" {
686+
host := strings.ReplaceAll(
687+
strings.ReplaceAll(
688+
g.cfg.HTTPListen, "0.0.0.0", "localhost",
689+
), "[::]", "localhost",
690+
)
691+
info.webURI = fmt.Sprintf("%s, http://%s", info.webURI, host)
692+
}
693+
662694
str := "" +
663695
"----------------------------------------------------------\n" +
664696
" Lightning Terminal (LiT) by Lightning Labs \n" +

0 commit comments

Comments
 (0)