Consistent HTTP setup

This commit is contained in:
Neil Alexander 2020-05-22 10:47:12 +01:00
parent a7ac34dad6
commit 9d44836cc3
4 changed files with 22 additions and 23 deletions

View file

@ -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() {

View file

@ -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() {

View file

@ -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 {

View file

@ -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))
}