From bd726f484dd5c8f6a8dd625e615bdb05999b5c1f Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sun, 15 Aug 2021 16:02:25 +0200 Subject: [PATCH] added not found and method not allowed handler for debugging --- backend/internal/router/router.go | 1 + backend/internal/router/routes.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/backend/internal/router/router.go b/backend/internal/router/router.go index 78d86e5..4c15842 100644 --- a/backend/internal/router/router.go +++ b/backend/internal/router/router.go @@ -11,6 +11,7 @@ import ( func ctxWrapper(appCtx *app.Context, handler web.Handler) httprouter.Handle { return func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) { writer.Header().Add("Content-Type", "application/json") + start := time.Now() handler(&web.Context{ Response: writer, diff --git a/backend/internal/router/routes.go b/backend/internal/router/routes.go index c991b0f..08fdd56 100644 --- a/backend/internal/router/routes.go +++ b/backend/internal/router/routes.go @@ -10,6 +10,16 @@ import ( func Setup(ctx *app.Context) http.Handler { router := &router{Router: httprouter.New(), appCtx: ctx} + router.NotFound = http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + ctx.AccessLog.Printf("%s %s; not found", request.Method, request.URL.String()) + writer.WriteHeader(http.StatusNotFound) + }) + + router.MethodNotAllowed = http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + ctx.AccessLog.Printf("%s %s; method not allowed", request.Method, request.URL.String()) + writer.WriteHeader(http.StatusMethodNotAllowed) + }) + router.POST("/authentication", Login) router.GET("/authentication", authenticated(GetAuthenticationData))