Use a "custom" http.Server for serving instead of just handler

This commit is contained in:
Melody Becker 2024-11-15 16:14:29 +01:00
parent 1f0dbda780
commit 526b5c2fef

View file

@ -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()
}