Separate muxes for public and internal APIs (#1056)

* Separate muxes for public and internal APIs

* Update client-api-proxy and federation-api-proxy so they don't add /api to the path

* Tidy up

* Consistent HTTP setup

* Set up prefixes properly
This commit is contained in:
Neil Alexander 2020-05-22 11:43:17 +01:00 committed by GitHub
parent f223da2f35
commit fe82e1f725
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 131 additions and 119 deletions

View file

@ -75,7 +75,6 @@ func makeProxy(targetURL string) (*httputil.ReverseProxy, error) {
// Pratically this means that any distinction between '%2F' and '/'
// in the URL will be lost by the time it reaches the target.
path := req.URL.Path
path = "api" + path
log.WithFields(log.Fields{
"path": path,
"url": targetURL,

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,12 +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)
httpHandler := internal.WrapHandlerInCORS(base.Base.APIMux)
// 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("/", httpHandler)
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,14 +90,13 @@ func main() {
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
httpHandler := internal.WrapHandlerInCORS(base.APIMux)
// 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("/", httpHandler)
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,9 +227,13 @@ func main() {
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
httpHandler := internal.WrapHandlerInCORS(base.APIMux)
http.Handle("/", httpHandler)
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

@ -73,7 +73,6 @@ func makeProxy(targetURL string) (*httputil.ReverseProxy, error) {
// Pratically this means that any distinction between '%2F' and '/'
// in the URL will be lost by the time it reaches the target.
path := req.URL.Path
path = "api" + path
log.WithFields(log.Fields{
"path": path,
"url": targetURL,