default 404 handler 등록

This commit is contained in:
2024-08-01 13:44:30 +09:00
parent 899bae335e
commit 7928e69c60

View File

@ -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},