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/matrix-org/dendrite/eduserver/cache"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -178,13 +177,13 @@ func main() {
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg) syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
// Set up the API endpoints we handle. /metrics is for prometheus, and is internal.SetupHTTPAPI(
// not wrapped by CORS, while everything else is http.DefaultServeMux,
http.Handle("/metrics", promhttp.Handler()) base.Base.PublicAPIMux,
http.Handle("/_matrix", internal.WrapHandlerInCORS(base.Base.PublicAPIMux)) base.Base.InternalAPIMux,
if base.Base.EnableHTTPAPIs { &cfg,
http.Handle("/api/", base.Base.InternalAPIMux) base.Base.EnableHTTPAPIs,
} )
// 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() {

View file

@ -35,7 +35,6 @@ import (
"github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/matrix-org/dendrite/publicroomsapi/storage"
"github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/syncapi" "github.com/matrix-org/dendrite/syncapi"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -91,15 +90,13 @@ func main() {
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil) publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
// Set up the API endpoints we handle. /metrics is for prometheus, and is internal.SetupHTTPAPI(
// not wrapped by CORS, while everything else is http.DefaultServeMux,
if cfg.Metrics.Enabled { base.PublicAPIMux,
http.Handle("/metrics", internal.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) base.InternalAPIMux,
} cfg,
http.Handle("/_matrix", internal.WrapHandlerInCORS(base.PublicAPIMux)) base.EnableHTTPAPIs,
if base.EnableHTTPAPIs { )
http.Handle("/api/", base.InternalAPIMux)
}
// 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() {

View file

@ -227,10 +227,13 @@ func main() {
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider) publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
http.Handle("/_matrix", internal.WrapHandlerInCORS(base.PublicAPIMux)) internal.SetupHTTPAPI(
if base.EnableHTTPAPIs { http.DefaultServeMux,
http.Handle("/api/", base.InternalAPIMux) base.PublicAPIMux,
} base.InternalAPIMux,
cfg,
base.EnableHTTPAPIs,
)
// Expose the matrix APIs via libp2p-js - for federation traffic // Expose the matrix APIs via libp2p-js - for federation traffic
if node != nil { 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)) servMux.Handle("/metrics", WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth))
} }
if enableHTTPAPIs { if enableHTTPAPIs {
servMux.Handle("/api/", internalApiMux) servMux.Handle("/api", internalApiMux)
} }
servMux.Handle("/_matrix", WrapHandlerInCORS(publicApiMux)) servMux.Handle("/_matrix", WrapHandlerInCORS(publicApiMux))
} }