diff --git a/http/handler.go b/http/handler.go index 2865a6807..77864ae74 100644 --- a/http/handler.go +++ b/http/handler.go @@ -67,6 +67,8 @@ type Handler struct { api *pilosa.API ln net.Listener + // url is used to hold the advertise bind address for printing a log during startup. + url string closeTimeout time.Duration @@ -135,9 +137,13 @@ func OptHandlerLogger(logger logger.Logger) handlerOption { } } -func OptHandlerListener(ln net.Listener) handlerOption { +// OptHandlerListener set the listener that will be used by the HTTP server. +// Url must be the advertised URL. It will be used to show a log to the user +// about where the Web UI is. This option is mandatory. +func OptHandlerListener(ln net.Listener, url string) handlerOption { return func(h *Handler) error { h.ln = ln + h.url = url return nil } } @@ -502,7 +508,7 @@ type statikHandler struct { func newStatikHandler(h *Handler) statikHandler { fs, err := h.fileSystem.New() if err == nil { - h.logger.Printf("enabled Web UI (%s) at %s", h.api.LatticeVersion(), h.ln.Addr().String()) + h.logger.Printf("enabled Web UI (%s) at %s", h.api.LatticeVersion(), h.url) } return statikHandler{ diff --git a/http/handler_test.go b/http/handler_test.go index 2d637f60f..2b4eaab32 100644 --- a/http/handler_test.go +++ b/http/handler_test.go @@ -45,7 +45,7 @@ func TestHandlerOptions(t *testing.T) { return err }, 10) - _, err = http.NewHandler(http.OptHandlerListener(ln)) + _, err = http.NewHandler(http.OptHandlerListener(ln, ln.Addr().String())) if err == nil { t.Fatalf("expected error making handler without options, got nil") } diff --git a/server/server.go b/server/server.go index 37b1b17c6..983cb7265 100644 --- a/server/server.go +++ b/server/server.go @@ -450,7 +450,7 @@ func (m *Command) SetupServer() error { http.OptHandlerAPI(m.API), http.OptHandlerLogger(m.logger), http.OptHandlerFileSystem(&statik.FileSystem{}), - http.OptHandlerListener(m.ln), + http.OptHandlerListener(m.ln, m.Config.Advertise), http.OptHandlerCloseTimeout(m.closeTimeout), http.OptHandlerMiddleware(m.grpcServer.middleware(m.Config.Handler.AllowedOrigins)), )