diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index b8e2109bf..bbd5035d3 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -178,13 +178,10 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg) - httpHandler := internal.WrapHandlerInCORS(base.Base.PublicAPIMux) - // Set up the API endpoints we handle. /metrics is for prometheus, and is // not wrapped by CORS, while everything else is http.Handle("/metrics", promhttp.Handler()) - http.Handle("/_matrix", httpHandler) - http.Handle("/_matrix", httpHandler) + http.Handle("/_matrix", internal.WrapHandlerInCORS(base.Base.PublicAPIMux)) if base.Base.EnableHTTPAPIs { http.Handle("/api/", base.Base.InternalAPIMux) } diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 898b840b1..78a11c0c6 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -91,14 +91,12 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - httpHandler := internal.WrapHandlerInCORS(base.PublicAPIMux) - // Set up the API endpoints we handle. /metrics is for prometheus, and is // not wrapped by CORS, while everything else is if cfg.Metrics.Enabled { http.Handle("/metrics", internal.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) } - http.Handle("/_matrix", httpHandler) + http.Handle("/_matrix", internal.WrapHandlerInCORS(base.PublicAPIMux)) if base.EnableHTTPAPIs { http.Handle("/api/", base.InternalAPIMux) } diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index d4489d75e..678126f74 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -227,8 +227,7 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - httpHandler := internal.WrapHandlerInCORS(base.PublicAPIMux) - http.Handle("/_matrix", httpHandler) + http.Handle("/_matrix", internal.WrapHandlerInCORS(base.PublicAPIMux)) if base.EnableHTTPAPIs { http.Handle("/api/", base.InternalAPIMux) } diff --git a/internal/basecomponent/base.go b/internal/basecomponent/base.go index 2684e6016..f75faf044 100644 --- a/internal/basecomponent/base.go +++ b/internal/basecomponent/base.go @@ -225,7 +225,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(bindaddr string, listenaddr string) { internal.SetupHTTPAPI( http.DefaultServeMux, - internal.WrapHandlerInCORS(b.PublicAPIMux), + b.PublicAPIMux, b.InternalAPIMux, b.Cfg, b.EnableHTTPAPIs, diff --git a/internal/httpapi.go b/internal/httpapi.go index 1117b3968..3558c4df4 100644 --- a/internal/httpapi.go +++ b/internal/httpapi.go @@ -191,7 +191,7 @@ func SetupHTTPAPI(servMux *http.ServeMux, publicApiMux http.Handler, internalApi if enableHTTPAPIs { servMux.Handle("/api/", internalApiMux) } - servMux.Handle("/_matrix", publicApiMux) + servMux.Handle("/_matrix", WrapHandlerInCORS(publicApiMux)) } // WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics