terminal: start additional HTTP listener

This commit is contained in:
Oliver Gugger 2020-12-17 18:19:29 +01:00
parent b23ae70a14
commit 2ebff9b611
No known key found for this signature in database
GPG key ID: 8E4256593F177720

View file

@ -592,6 +592,28 @@ func (g *LightningTerminal) startMainWebServer() error {
}
}()
// We only enable an additional HTTP only listener if the user
// explicitly sets a value.
if g.cfg.HTTPListen != "" {
insecureListener, err := net.Listen("tcp", g.cfg.HTTPListen)
if err != nil {
return fmt.Errorf("unable to listen on %v: %v",
g.cfg.HTTPListen, err)
}
g.wg.Add(1)
go func() {
defer g.wg.Done()
log.Infof("Listening for http on: %v",
insecureListener.Addr())
err := g.httpServer.Serve(insecureListener)
if err != nil && err != http.ErrServerClosed {
log.Errorf("http server error: %v", err)
}
}()
}
return nil
}
@ -611,8 +633,8 @@ func (g *LightningTerminal) showStartupInfo() error {
version: build.Version(),
webURI: fmt.Sprintf("https://%s", strings.ReplaceAll(
strings.ReplaceAll(
g.cfg.HTTPSListen, "0.0.0.0", "127.0.0.1",
), "[::]", "[::1]",
g.cfg.HTTPSListen, "0.0.0.0", "localhost",
), "[::]", "localhost",
)),
}
@ -659,6 +681,16 @@ func (g *LightningTerminal) showStartupInfo() error {
}
}
// If there's an additional HTTP listener, list it as well.
if g.cfg.HTTPListen != "" {
host := strings.ReplaceAll(
strings.ReplaceAll(
g.cfg.HTTPListen, "0.0.0.0", "localhost",
), "[::]", "localhost",
)
info.webURI = fmt.Sprintf("%s, http://%s", info.webURI, host)
}
str := "" +
"----------------------------------------------------------\n" +
" Lightning Terminal (LiT) by Lightning Labs \n" +