diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index bbd5035d3..3f53cb429 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -47,7 +47,6 @@ import ( "github.com/matrix-org/dendrite/eduserver/cache" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" ) @@ -178,13 +177,13 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg) - // 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", internal.WrapHandlerInCORS(base.Base.PublicAPIMux)) - if base.Base.EnableHTTPAPIs { - http.Handle("/api/", base.Base.InternalAPIMux) - } + internal.SetupHTTPAPI( + http.DefaultServeMux, + base.Base.PublicAPIMux, + base.Base.InternalAPIMux, + &cfg, + base.Base.EnableHTTPAPIs, + ) // Expose the matrix APIs directly rather than putting them under a /api path. go func() { diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 78a11c0c6..0042a9b9c 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -35,7 +35,6 @@ import ( "github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/syncapi" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" ) @@ -91,15 +90,13 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - // 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", internal.WrapHandlerInCORS(base.PublicAPIMux)) - if base.EnableHTTPAPIs { - http.Handle("/api/", base.InternalAPIMux) - } + internal.SetupHTTPAPI( + http.DefaultServeMux, + base.PublicAPIMux, + base.InternalAPIMux, + cfg, + base.EnableHTTPAPIs, + ) // Expose the matrix APIs directly rather than putting them under a /api path. go func() { diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 678126f74..1398bc6da 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -227,10 +227,13 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - http.Handle("/_matrix", internal.WrapHandlerInCORS(base.PublicAPIMux)) - if base.EnableHTTPAPIs { - http.Handle("/api/", base.InternalAPIMux) - } + internal.SetupHTTPAPI( + http.DefaultServeMux, + base.PublicAPIMux, + base.InternalAPIMux, + cfg, + base.EnableHTTPAPIs, + ) // Expose the matrix APIs via libp2p-js - for federation traffic if node != nil { diff --git a/internal/httpapi.go b/internal/httpapi.go index 3558c4df4..0d50ff932 100644 --- a/internal/httpapi.go +++ b/internal/httpapi.go @@ -189,7 +189,7 @@ func SetupHTTPAPI(servMux *http.ServeMux, publicApiMux http.Handler, internalApi servMux.Handle("/metrics", WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) } if enableHTTPAPIs { - servMux.Handle("/api/", internalApiMux) + servMux.Handle("/api", internalApiMux) } servMux.Handle("/_matrix", WrapHandlerInCORS(publicApiMux)) }