From 7928e69c6073f7ba625676ce739ca863b34d5434 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 1 Aug 2024 13:44:30 +0900 Subject: [PATCH] =?UTF-8?q?default=20404=20handler=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.go b/server.go index 2556086..f2caa39 100644 --- a/server.go +++ b/server.go @@ -146,6 +146,17 @@ func isTlsEnabled(fileout ...*string) bool { return true } +func registUnhandledPattern(serveMux ServerMuxInterface) { + defer func() { + recover() + }() + + serveMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + logger.Println("page not found :", r.URL.Path) + w.WriteHeader(http.StatusNotFound) + }) +} + // NewHTTPServer : func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server { if isTlsEnabled() && port == 80 { @@ -155,6 +166,7 @@ func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server { serveMux.HandleFunc(MakeHttpHandlerPattern("welcome"), welcomeHandler) serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_chceck"), healthCheckHandler) serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_check"), healthCheckHandler) + registUnhandledPattern(serveMux) server := &Server{ httpserver: &http.Server{Addr: addr, Handler: serveMux},