mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-06 22:43:10 -06:00
clean up
This commit is contained in:
parent
24b93e4d23
commit
b9c605abf0
|
|
@ -170,7 +170,7 @@ func main() {
|
||||||
|
|
||||||
// Expose the matrix APIs directly rather than putting them under a /api path.
|
// Expose the matrix APIs directly rather than putting them under a /api path.
|
||||||
go func() {
|
go func() {
|
||||||
SetupAndServeHTTP(processCtx, cfg, routers) //, httpsAddr, nil, nil)
|
SetupAndServeHTTPS(processCtx, cfg, routers) //, httpsAddr, nil, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// We want to block forever to let the HTTP and HTTPS handler serve the APIs
|
// We want to block forever to let the HTTP and HTTPS handler serve the APIs
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,9 @@ func Dial(network, addr string) (net.Conn, error) {
|
||||||
//go:embed static/*.gotmpl
|
//go:embed static/*.gotmpl
|
||||||
var staticContent embed.FS
|
var staticContent embed.FS
|
||||||
|
|
||||||
// SetupAndServeHTTP sets up the HTTP server to serve client & federation APIs
|
// SetupAndServeHTTPS sets up the HTTPS server to serve client & federation APIs
|
||||||
// and adds a prometheus handler under /_dendrite/metrics.
|
// and adds a prometheus handler under /_dendrite/metrics.
|
||||||
func SetupAndServeHTTP(
|
func SetupAndServeHTTPS(
|
||||||
processContext *process.ProcessContext,
|
processContext *process.ProcessContext,
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
routers httputil.Routers,
|
routers httputil.Routers,
|
||||||
|
|
@ -93,21 +93,21 @@ func SetupAndServeHTTP(
|
||||||
defer garlic.Close()
|
defer garlic.Close()
|
||||||
listener, err := garlic.ListenTLS()
|
listener, err := garlic.ListenTLS()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("failed to serve HTTP")
|
logrus.WithError(err).Fatal("failed to serve HTTPS")
|
||||||
}
|
}
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
externalHTTPAddr := config.ServerAddress{}
|
externalHTTPSAddr := config.ServerAddress{}
|
||||||
https, err := config.HTTPAddress("https://" + listener.Addr().String())
|
https, err := config.HTTPAddress("https://" + listener.Addr().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatalf("Failed to parse http address")
|
logrus.WithError(err).Fatalf("Failed to parse http address")
|
||||||
}
|
}
|
||||||
externalHTTPAddr = https
|
externalHTTPSAddr = https
|
||||||
|
|
||||||
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
|
|
||||||
externalServ := &http.Server{
|
externalServ := &http.Server{
|
||||||
Addr: externalHTTPAddr.Address,
|
Addr: externalHTTPSAddr.Address,
|
||||||
WriteTimeout: basepkg.HTTPServerTimeout,
|
WriteTimeout: basepkg.HTTPServerTimeout,
|
||||||
Handler: externalRouter,
|
Handler: externalRouter,
|
||||||
BaseContext: func(_ net.Listener) context.Context {
|
BaseContext: func(_ net.Listener) context.Context {
|
||||||
|
|
@ -169,22 +169,22 @@ func SetupAndServeHTTP(
|
||||||
externalRouter.NotFoundHandler = httputil.NotFoundCORSHandler
|
externalRouter.NotFoundHandler = httputil.NotFoundCORSHandler
|
||||||
externalRouter.MethodNotAllowedHandler = httputil.NotAllowedHandler
|
externalRouter.MethodNotAllowedHandler = httputil.NotAllowedHandler
|
||||||
|
|
||||||
if externalHTTPAddr.Enabled() {
|
if externalHTTPSAddr.Enabled() {
|
||||||
go func() {
|
go func() {
|
||||||
var externalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
|
var externalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
|
||||||
logrus.Infof("Starting external listener on %s", externalServ.Addr)
|
logrus.Infof("Starting external listener on https://%s", externalServ.Addr)
|
||||||
processContext.ComponentStarted()
|
processContext.ComponentStarted()
|
||||||
externalServ.RegisterOnShutdown(func() {
|
externalServ.RegisterOnShutdown(func() {
|
||||||
if externalShutdown.CompareAndSwap(false, true) {
|
if externalShutdown.CompareAndSwap(false, true) {
|
||||||
processContext.ComponentFinished()
|
processContext.ComponentFinished()
|
||||||
logrus.Infof("Stopped external HTTP listener")
|
logrus.Infof("Stopped external HTTPS listener")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
addr := listener.Addr()
|
addr := listener.Addr()
|
||||||
externalServ.Addr = addr.String()
|
externalServ.Addr = addr.String()
|
||||||
if err := externalServ.Serve(listener); err != nil {
|
if err := externalServ.Serve(listener); err != nil {
|
||||||
if err != http.ErrServerClosed {
|
if err != http.ErrServerClosed {
|
||||||
logrus.WithError(err).Fatal("failed to serve HTTP")
|
logrus.WithError(err).Fatal("failed to serve HTTPS")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,7 +195,7 @@ func SetupAndServeHTTP(
|
||||||
minwinsvc.SetOnExit(processContext.ShutdownDendrite)
|
minwinsvc.SetOnExit(processContext.ShutdownDendrite)
|
||||||
<-processContext.WaitForShutdown()
|
<-processContext.WaitForShutdown()
|
||||||
|
|
||||||
logrus.Infof("Stopping HTTP listeners")
|
logrus.Infof("Stopping HTTPS listeners")
|
||||||
_ = externalServ.Shutdown(context.Background())
|
_ = externalServ.Shutdown(context.Background())
|
||||||
logrus.Infof("Stopped HTTP listeners")
|
logrus.Infof("Stopped HTTPS listeners")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue