From 0835a914f3bc806de77bfb4acc4b52412b87e325 Mon Sep 17 00:00:00 2001 From: Julliano Goncalves Date: Wed, 3 Aug 2022 16:58:09 -0300 Subject: [PATCH] Add route to HealthCheck (useful in deployments to GKE) Signed-off-by: Julliano Goncalves --- vendor/github.com/mailhog/MailHog-UI/web/web.go | 10 ++++++++++ vendor/github.com/mailhog/http/server.go | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vendor/github.com/mailhog/MailHog-UI/web/web.go b/vendor/github.com/mailhog/MailHog-UI/web/web.go index 901109a4..f1eb266a 100644 --- a/vendor/github.com/mailhog/MailHog-UI/web/web.go +++ b/vendor/github.com/mailhog/MailHog-UI/web/web.go @@ -37,11 +37,21 @@ func CreateWeb(cfg *config.Config, r http.Handler, asset func(string) ([]byte, e pat.Path(WebPath + "/css/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/css/{{file}}")) pat.Path(WebPath + "/js/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/js/{{file}}")) pat.Path(WebPath + "/fonts/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/fonts/{{file}}")) + pat.Path(WebPath + "/healthz").Methods("GET").HandlerFunc(web.HealthCheck()) pat.StrictSlash(true).Path(WebPath + "/").Methods("GET").HandlerFunc(web.Index()) return web } +func (web Web) HealthCheck() func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, req *http.Request) { + log.Println("[UI] GET /healthz") + + w.WriteHeader(200) + w.Write([]byte("UP")) + } +} + func (web Web) Static(pattern string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, req *http.Request) { fp := strings.TrimSuffix(pattern, "{{file}}") + req.URL.Query().Get(":file") diff --git a/vendor/github.com/mailhog/http/server.go b/vendor/github.com/mailhog/http/server.go index 6c7e7c2f..279f4f05 100644 --- a/vendor/github.com/mailhog/http/server.go +++ b/vendor/github.com/mailhog/http/server.go @@ -84,7 +84,8 @@ func BasicAuthHandler(h http.Handler) http.Handler { } u, pw, ok := req.BasicAuth() - if !ok || !Authorised(u, pw) { + + if (req.URL.Path != "/healthz") && (!ok || !Authorised(u, pw)) { w.Header().Set("WWW-Authenticate", "Basic") w.WriteHeader(401) return