Use a "custom" http.Server for serving instead of just handler
This commit is contained in:
parent
1f0dbda780
commit
526b5c2fef
1 changed files with 8 additions and 1 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
type Server struct {
|
type Server struct {
|
||||||
store *storage.Storage
|
store *storage.Storage
|
||||||
router http.Handler
|
router http.Handler
|
||||||
|
server *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(
|
func NewServer(
|
||||||
|
@ -26,9 +27,14 @@ func NewServer(
|
||||||
handler = ChainMiddlewares(handler, LoggingMiddleware, ContextValsMiddleware(map[any]any{
|
handler = ChainMiddlewares(handler, LoggingMiddleware, ContextValsMiddleware(map[any]any{
|
||||||
ContextKeyStorage: store,
|
ContextKeyStorage: store,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
server := http.Server{
|
||||||
|
Handler: handler,
|
||||||
|
}
|
||||||
return &Server{
|
return &Server{
|
||||||
store: store,
|
store: store,
|
||||||
router: handler,
|
router: handler,
|
||||||
|
server: &server,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,5 +92,6 @@ func buildPasskeyAuthRouter(pkey *passkey.Passkey) http.Handler {
|
||||||
|
|
||||||
func (s *Server) Start(addr string) error {
|
func (s *Server) Start(addr string) error {
|
||||||
log.Info().Str("addr", addr).Msg("Starting server")
|
log.Info().Str("addr", addr).Msg("Starting server")
|
||||||
return http.ListenAndServe(addr, s.router)
|
s.server.Addr = addr
|
||||||
|
return s.server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue