From 526b5c2fef0a2045db0837b06bcb982361b73e7a Mon Sep 17 00:00:00 2001 From: mStar Date: Fri, 15 Nov 2024 16:14:29 +0100 Subject: [PATCH] Use a "custom" http.Server for serving instead of just handler --- server/server.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 32ef801..91cedff 100644 --- a/server/server.go +++ b/server/server.go @@ -14,6 +14,7 @@ import ( type Server struct { store *storage.Storage router http.Handler + server *http.Server } func NewServer( @@ -26,9 +27,14 @@ func NewServer( handler = ChainMiddlewares(handler, LoggingMiddleware, ContextValsMiddleware(map[any]any{ ContextKeyStorage: store, })) + + server := http.Server{ + Handler: handler, + } return &Server{ store: store, router: handler, + server: &server, } } @@ -86,5 +92,6 @@ func buildPasskeyAuthRouter(pkey *passkey.Passkey) http.Handler { func (s *Server) Start(addr string) error { log.Info().Str("addr", addr).Msg("Starting server") - return http.ListenAndServe(addr, s.router) + s.server.Addr = addr + return s.server.ListenAndServe() }