http: fix serve http exits directly after starting

This commit is contained in:
Cnly 2021-07-24 18:01:58 +08:00 committed by Nick Craig-Wood
parent f39a08c9d7
commit bc74f0621e
2 changed files with 11 additions and 0 deletions

View File

@ -69,6 +69,7 @@ control the stats printing.
return err
}
s.Bind(router)
httplib.Wait()
return nil
})
},

View File

@ -231,6 +231,11 @@ func (s *server) Serve() {
}
}
// Wait blocks while the server is serving requests
func (s *server) Wait() {
s.closing.Wait()
}
// Router returns the server base router
func (s *server) Router() chi.Router {
return s.baseRouter
@ -291,6 +296,11 @@ func Restart() error {
return start()
}
// Wait blocks while the default http server is serving requests
func Wait() {
defaultServer.Wait()
}
// Start the default server
func start() error {
defaultServerMutex.Lock()