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
main
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

@ -101,7 +101,7 @@ func SetupAppServiceAPIComponent(
// Set up HTTP Endpoints // Set up HTTP Endpoints
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, rsAPI, base.PublicAPIMux, base.Cfg, rsAPI,
accountsDB, federation, transactionsCache, accountsDB, federation, transactionsCache,
) )

View File

@ -27,7 +27,7 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
const pathPrefixApp = "/_matrix/app/v1" const pathPrefixApp = "/app/v1"
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests. // to clients which need to make outbound HTTP requests.

View File

@ -65,7 +65,7 @@ func SetupClientAPIComponent(
} }
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, roomserverProducer, rsAPI, asAPI, base.PublicAPIMux, base.Cfg, roomserverProducer, rsAPI, asAPI,
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer, accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
syncProducer, eduProducer, transactionsCache, fsAPI, syncProducer, eduProducer, transactionsCache, fsAPI,
) )

View File

@ -36,9 +36,9 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
const pathPrefixV1 = "/_matrix/client/api/v1" const pathPrefixV1 = "/client/api/v1"
const pathPrefixR0 = "/_matrix/client/r0" const pathPrefixR0 = "/client/r0"
const pathPrefixUnstable = "/_matrix/client/unstable" const pathPrefixUnstable = "/client/unstable"
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests. // to clients which need to make outbound HTTP requests.
@ -47,7 +47,7 @@ const pathPrefixUnstable = "/_matrix/client/unstable"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, cfg *config.Dendrite, publicAPIMux *mux.Router, cfg *config.Dendrite,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
rsAPI roomserverAPI.RoomserverInternalAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
@ -62,7 +62,7 @@ func Setup(
federationSender federationSenderAPI.FederationSenderInternalAPI, federationSender federationSenderAPI.FederationSenderInternalAPI,
) { ) {
apiMux.Handle("/_matrix/client/versions", publicAPIMux.Handle("/client/versions",
internal.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse { internal.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusOK, Code: http.StatusOK,
@ -78,9 +78,9 @@ func Setup(
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
v1mux := apiMux.PathPrefix(pathPrefixV1).Subrouter() v1mux := publicAPIMux.PathPrefix(pathPrefixV1).Subrouter()
unstableMux := apiMux.PathPrefix(pathPrefixUnstable).Subrouter() unstableMux := publicAPIMux.PathPrefix(pathPrefixUnstable).Subrouter()
authData := auth.Data{ authData := auth.Data{
AccountDB: accountDB, AccountDB: accountDB,

View File

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

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,12 +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)
httpHandler := internal.WrapHandlerInCORS(base.Base.APIMux) internal.SetupHTTPAPI(
http.DefaultServeMux,
// Set up the API endpoints we handle. /metrics is for prometheus, and is base.Base.PublicAPIMux,
// not wrapped by CORS, while everything else is base.Base.InternalAPIMux,
http.Handle("/metrics", promhttp.Handler()) &cfg,
http.Handle("/", httpHandler) 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,14 +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)
httpHandler := internal.WrapHandlerInCORS(base.APIMux) internal.SetupHTTPAPI(
http.DefaultServeMux,
// Set up the API endpoints we handle. /metrics is for prometheus, and is base.PublicAPIMux,
// not wrapped by CORS, while everything else is base.InternalAPIMux,
if cfg.Metrics.Enabled { cfg,
http.Handle("/metrics", internal.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) base.EnableHTTPAPIs,
} )
http.Handle("/", httpHandler)
// 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,9 +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)
httpHandler := internal.WrapHandlerInCORS(base.APIMux) internal.SetupHTTPAPI(
http.DefaultServeMux,
http.Handle("/", httpHandler) 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

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

View File

@ -44,7 +44,7 @@ func SetupFederationAPIComponent(
roomserverProducer := producers.NewRoomserverProducer(rsAPI) roomserverProducer := producers.NewRoomserverProducer(rsAPI)
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, rsAPI, asAPI, roomserverProducer, base.PublicAPIMux, base.Cfg, rsAPI, asAPI, roomserverProducer,
eduProducer, federationSenderAPI, *keyRing, eduProducer, federationSenderAPI, *keyRing,
federation, accountsDB, deviceDB, federation, accountsDB, deviceDB,
) )

View File

@ -31,9 +31,9 @@ import (
) )
const ( const (
pathPrefixV2Keys = "/_matrix/key/v2" pathPrefixV2Keys = "/key/v2"
pathPrefixV1Federation = "/_matrix/federation/v1" pathPrefixV1Federation = "/federation/v1"
pathPrefixV2Federation = "/_matrix/federation/v2" pathPrefixV2Federation = "/federation/v2"
) )
// Setup registers HTTP handlers with the given ServeMux. // Setup registers HTTP handlers with the given ServeMux.
@ -42,7 +42,7 @@ const (
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, publicAPIMux *mux.Router,
cfg *config.Dendrite, cfg *config.Dendrite,
rsAPI roomserverAPI.RoomserverInternalAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
@ -54,9 +54,9 @@ func Setup(
accountDB accounts.Database, accountDB accounts.Database,
deviceDB devices.Database, deviceDB devices.Database,
) { ) {
v2keysmux := apiMux.PathPrefix(pathPrefixV2Keys).Subrouter() v2keysmux := publicAPIMux.PathPrefix(pathPrefixV2Keys).Subrouter()
v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter() v1fedmux := publicAPIMux.PathPrefix(pathPrefixV1Federation).Subrouter()
v2fedmux := apiMux.PathPrefix(pathPrefixV2Federation).Subrouter() v2fedmux := publicAPIMux.PathPrefix(pathPrefixV2Federation).Subrouter()
localKeys := internal.MakeExternalAPI("localkeys", func(req *http.Request) util.JSONResponse { localKeys := internal.MakeExternalAPI("localkeys", func(req *http.Request) util.JSONResponse {
return LocalKeys(cfg) return LocalKeys(cfg)

View File

@ -15,8 +15,6 @@
package federationsender package federationsender
import ( import (
"net/http"
"github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/federationsender/consumers" "github.com/matrix-org/dendrite/federationsender/consumers"
"github.com/matrix-org/dendrite/federationsender/internal" "github.com/matrix-org/dendrite/federationsender/internal"
@ -72,9 +70,7 @@ func SetupFederationSenderComponent(
statistics, statistics,
) )
if base.EnableHTTPAPIs { queryAPI.SetupHTTP(base.InternalAPIMux)
queryAPI.SetupHTTP(http.DefaultServeMux)
}
return queryAPI return queryAPI
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/federationsender/producers" "github.com/matrix-org/dendrite/federationsender/producers"
"github.com/matrix-org/dendrite/federationsender/storage" "github.com/matrix-org/dendrite/federationsender/storage"
@ -43,8 +44,8 @@ func NewFederationSenderInternalAPI(
} }
// SetupHTTP adds the FederationSenderInternalAPI handlers to the http.ServeMux. // SetupHTTP adds the FederationSenderInternalAPI handlers to the http.ServeMux.
func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) { func (f *FederationSenderInternalAPI) SetupHTTP(internalAPIMux *mux.Router) {
servMux.Handle( internalAPIMux.Handle(
api.FederationSenderQueryJoinedHostsInRoomPath, api.FederationSenderQueryJoinedHostsInRoomPath,
internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryJoinedHostsInRoomRequest var request api.QueryJoinedHostsInRoomRequest
@ -58,7 +59,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.FederationSenderQueryJoinedHostServerNamesInRoomPath, api.FederationSenderQueryJoinedHostServerNamesInRoomPath,
internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryJoinedHostServerNamesInRoomRequest var request api.QueryJoinedHostServerNamesInRoomRequest
@ -72,7 +73,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle(api.FederationSenderPerformJoinRequestPath, internalAPIMux.Handle(api.FederationSenderPerformJoinRequestPath,
internal.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse {
var request api.PerformJoinRequest var request api.PerformJoinRequest
var response api.PerformJoinResponse var response api.PerformJoinResponse
@ -85,7 +86,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle(api.FederationSenderPerformLeaveRequestPath, internalAPIMux.Handle(api.FederationSenderPerformLeaveRequestPath,
internal.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse {
var request api.PerformLeaveRequest var request api.PerformLeaveRequest
var response api.PerformLeaveResponse var response api.PerformLeaveResponse

View File

@ -56,8 +56,9 @@ type BaseDendrite struct {
componentName string componentName string
tracerCloser io.Closer tracerCloser io.Closer
// APIMux should be used to register new public matrix api endpoints // PublicAPIMux should be used to register new public matrix api endpoints
APIMux *mux.Router PublicAPIMux *mux.Router
InternalAPIMux *mux.Router
EnableHTTPAPIs bool EnableHTTPAPIs bool
httpClient *http.Client httpClient *http.Client
Cfg *config.Dendrite Cfg *config.Dendrite
@ -95,13 +96,15 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs
logrus.WithError(err).Warnf("Failed to create cache") logrus.WithError(err).Warnf("Failed to create cache")
} }
httpmux := mux.NewRouter()
return &BaseDendrite{ return &BaseDendrite{
componentName: componentName, componentName: componentName,
EnableHTTPAPIs: enableHTTPAPIs, EnableHTTPAPIs: enableHTTPAPIs,
tracerCloser: closer, tracerCloser: closer,
Cfg: cfg, Cfg: cfg,
ImmutableCache: cache, ImmutableCache: cache,
APIMux: mux.NewRouter().UseEncodedPath(), PublicAPIMux: httpmux.PathPrefix(internal.HTTPPublicPathPrefix).Subrouter().UseEncodedPath(),
InternalAPIMux: httpmux.PathPrefix(internal.HTTPInternalPathPrefix).Subrouter().UseEncodedPath(),
httpClient: &http.Client{Timeout: HTTPClientTimeout}, httpClient: &http.Client{Timeout: HTTPClientTimeout},
KafkaConsumer: kafkaConsumer, KafkaConsumer: kafkaConsumer,
KafkaProducer: kafkaProducer, KafkaProducer: kafkaProducer,
@ -221,7 +224,13 @@ func (b *BaseDendrite) SetupAndServeHTTP(bindaddr string, listenaddr string) {
WriteTimeout: HTTPServerTimeout, WriteTimeout: HTTPServerTimeout,
} }
internal.SetupHTTPAPI(http.DefaultServeMux, internal.WrapHandlerInCORS(b.APIMux), b.Cfg) internal.SetupHTTPAPI(
http.DefaultServeMux,
b.PublicAPIMux,
b.InternalAPIMux,
b.Cfg,
b.EnableHTTPAPIs,
)
logrus.Infof("Starting %s server on %s", b.componentName, serv.Addr) logrus.Infof("Starting %s server on %s", b.componentName, serv.Addr)
err := serv.ListenAndServe() err := serv.ListenAndServe()

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/internal/config"
@ -22,6 +23,11 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const (
HTTPPublicPathPrefix = "/_matrix/"
HTTPInternalPathPrefix = "/api/"
)
// BasicAuth is used for authorization on /metrics handlers // BasicAuth is used for authorization on /metrics handlers
type BasicAuth struct { type BasicAuth struct {
Username string `yaml:"username"` Username string `yaml:"username"`
@ -184,11 +190,14 @@ func MakeFedAPI(
// SetupHTTPAPI registers an HTTP API mux under /api and sets up a metrics // SetupHTTPAPI registers an HTTP API mux under /api and sets up a metrics
// listener. // listener.
func SetupHTTPAPI(servMux *http.ServeMux, apiMux http.Handler, cfg *config.Dendrite) { func SetupHTTPAPI(servMux *http.ServeMux, publicApiMux *mux.Router, internalApiMux *mux.Router, cfg *config.Dendrite, enableHTTPAPIs bool) {
if cfg.Metrics.Enabled { if cfg.Metrics.Enabled {
servMux.Handle("/metrics", WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) servMux.Handle("/metrics", WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth))
} }
servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) if enableHTTPAPIs {
servMux.Handle(HTTPInternalPathPrefix, internalApiMux)
}
servMux.Handle(HTTPPublicPathPrefix, WrapHandlerInCORS(publicApiMux))
} }
// WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics // WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics

View File

@ -28,5 +28,5 @@ func SetupKeyServerComponent(
deviceDB devices.Database, deviceDB devices.Database,
accountsDB accounts.Database, accountsDB accounts.Database,
) { ) {
routing.Setup(base.APIMux, base.Cfg, accountsDB, deviceDB) routing.Setup(base.PublicAPIMux, base.Cfg, accountsDB, deviceDB)
} }

View File

@ -27,7 +27,7 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
const pathPrefixR0 = "/_matrix/client/r0" const pathPrefixR0 = "/client/r0"
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests. // to clients which need to make outbound HTTP requests.
@ -36,11 +36,11 @@ const pathPrefixR0 = "/_matrix/client/r0"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, cfg *config.Dendrite, publicAPIMux *mux.Router, cfg *config.Dendrite,
accountDB accounts.Database, accountDB accounts.Database,
deviceDB devices.Database, deviceDB devices.Database,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
authData := auth.Data{ authData := auth.Data{
AccountDB: accountDB, AccountDB: accountDB,

View File

@ -35,6 +35,6 @@ func SetupMediaAPIComponent(
} }
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(), base.PublicAPIMux, base.Cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(),
) )
} }

View File

@ -33,7 +33,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
const pathPrefixR0 = "/_matrix/media/r0" const pathPrefixR0 = "/media/r0"
// Setup registers the media API HTTP handlers // Setup registers the media API HTTP handlers
// //
@ -41,13 +41,13 @@ const pathPrefixR0 = "/_matrix/media/r0"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, publicAPIMux *mux.Router,
cfg *config.Dendrite, cfg *config.Dendrite,
db storage.Database, db storage.Database,
deviceDB devices.Database, deviceDB devices.Database,
client *gomatrixserverlib.Client, client *gomatrixserverlib.Client,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{ activeThumbnailGeneration := &types.ActiveThumbnailGeneration{
PathToResult: map[string]*types.ThumbnailGenerationResult{}, PathToResult: map[string]*types.ThumbnailGenerationResult{},

View File

@ -43,5 +43,5 @@ func SetupPublicRoomsAPIComponent(
logrus.WithError(err).Panic("failed to start public rooms server consumer") logrus.WithError(err).Panic("failed to start public rooms server consumer")
} }
routing.Setup(base.APIMux, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider) routing.Setup(base.PublicAPIMux, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
} }

View File

@ -31,7 +31,7 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
const pathPrefixR0 = "/_matrix/client/r0" const pathPrefixR0 = "/client/r0"
// Setup configures the given mux with publicroomsapi server listeners // Setup configures the given mux with publicroomsapi server listeners
// //
@ -39,10 +39,10 @@ const pathPrefixR0 = "/_matrix/client/r0"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database, rsAPI api.RoomserverInternalAPI, publicAPIMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database, rsAPI api.RoomserverInternalAPI,
fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider, fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
authData := auth.Data{ authData := auth.Data{
AccountDB: nil, AccountDB: nil,
@ -79,7 +79,7 @@ func Setup(
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions) ).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
// Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is. // Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is.
apiMux.Handle("/_matrix/federation/v1/publicRooms", publicAPIMux.Handle("/federation/v1/publicRooms",
internal.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse { internal.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse {
return directory.GetPostPublicRooms(req, publicRoomsDB) return directory.GetPostPublicRooms(req, publicRoomsDB)
}), }),

View File

@ -85,19 +85,19 @@ type RemoveRoomAliasRequest struct {
type RemoveRoomAliasResponse struct{} type RemoveRoomAliasResponse struct{}
// RoomserverSetRoomAliasPath is the HTTP path for the SetRoomAlias API. // RoomserverSetRoomAliasPath is the HTTP path for the SetRoomAlias API.
const RoomserverSetRoomAliasPath = "/api/roomserver/setRoomAlias" const RoomserverSetRoomAliasPath = "/roomserver/setRoomAlias"
// RoomserverGetRoomIDForAliasPath is the HTTP path for the GetRoomIDForAlias API. // RoomserverGetRoomIDForAliasPath is the HTTP path for the GetRoomIDForAlias API.
const RoomserverGetRoomIDForAliasPath = "/api/roomserver/GetRoomIDForAlias" const RoomserverGetRoomIDForAliasPath = "/roomserver/GetRoomIDForAlias"
// RoomserverGetAliasesForRoomIDPath is the HTTP path for the GetAliasesForRoomID API. // RoomserverGetAliasesForRoomIDPath is the HTTP path for the GetAliasesForRoomID API.
const RoomserverGetAliasesForRoomIDPath = "/api/roomserver/GetAliasesForRoomID" const RoomserverGetAliasesForRoomIDPath = "/roomserver/GetAliasesForRoomID"
// RoomserverGetCreatorIDForAliasPath is the HTTP path for the GetCreatorIDForAlias API. // RoomserverGetCreatorIDForAliasPath is the HTTP path for the GetCreatorIDForAlias API.
const RoomserverGetCreatorIDForAliasPath = "/api/roomserver/GetCreatorIDForAlias" const RoomserverGetCreatorIDForAliasPath = "/roomserver/GetCreatorIDForAlias"
// RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API. // RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API.
const RoomserverRemoveRoomAliasPath = "/api/roomserver/removeRoomAlias" const RoomserverRemoveRoomAliasPath = "/roomserver/removeRoomAlias"
// SetRoomAlias implements RoomserverAliasAPI // SetRoomAlias implements RoomserverAliasAPI
func (h *httpRoomserverInternalAPI) SetRoomAlias( func (h *httpRoomserverInternalAPI) SetRoomAlias(

View File

@ -103,7 +103,7 @@ type InputRoomEventsResponse struct {
} }
// RoomserverInputRoomEventsPath is the HTTP path for the InputRoomEvents API. // RoomserverInputRoomEventsPath is the HTTP path for the InputRoomEvents API.
const RoomserverInputRoomEventsPath = "/api/roomserver/inputRoomEvents" const RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents"
// InputRoomEvents implements RoomserverInputAPI // InputRoomEvents implements RoomserverInputAPI
func (h *httpRoomserverInternalAPI) InputRoomEvents( func (h *httpRoomserverInternalAPI) InputRoomEvents(

View File

@ -10,10 +10,10 @@ import (
const ( const (
// RoomserverPerformJoinPath is the HTTP path for the PerformJoin API. // RoomserverPerformJoinPath is the HTTP path for the PerformJoin API.
RoomserverPerformJoinPath = "/api/roomserver/performJoin" RoomserverPerformJoinPath = "/roomserver/performJoin"
// RoomserverPerformLeavePath is the HTTP path for the PerformLeave API. // RoomserverPerformLeavePath is the HTTP path for the PerformLeave API.
RoomserverPerformLeavePath = "/api/roomserver/performLeave" RoomserverPerformLeavePath = "/roomserver/performLeave"
) )
type PerformJoinRequest struct { type PerformJoinRequest struct {

View File

@ -273,40 +273,40 @@ type QueryRoomVersionForRoomResponse struct {
} }
// RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API. // RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API.
const RoomserverQueryLatestEventsAndStatePath = "/api/roomserver/queryLatestEventsAndState" const RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState"
// RoomserverQueryStateAfterEventsPath is the HTTP path for the QueryStateAfterEvents API. // RoomserverQueryStateAfterEventsPath is the HTTP path for the QueryStateAfterEvents API.
const RoomserverQueryStateAfterEventsPath = "/api/roomserver/queryStateAfterEvents" const RoomserverQueryStateAfterEventsPath = "/roomserver/queryStateAfterEvents"
// RoomserverQueryEventsByIDPath is the HTTP path for the QueryEventsByID API. // RoomserverQueryEventsByIDPath is the HTTP path for the QueryEventsByID API.
const RoomserverQueryEventsByIDPath = "/api/roomserver/queryEventsByID" const RoomserverQueryEventsByIDPath = "/roomserver/queryEventsByID"
// RoomserverQueryMembershipForUserPath is the HTTP path for the QueryMembershipForUser API. // RoomserverQueryMembershipForUserPath is the HTTP path for the QueryMembershipForUser API.
const RoomserverQueryMembershipForUserPath = "/api/roomserver/queryMembershipForUser" const RoomserverQueryMembershipForUserPath = "/roomserver/queryMembershipForUser"
// RoomserverQueryMembershipsForRoomPath is the HTTP path for the QueryMembershipsForRoom API // RoomserverQueryMembershipsForRoomPath is the HTTP path for the QueryMembershipsForRoom API
const RoomserverQueryMembershipsForRoomPath = "/api/roomserver/queryMembershipsForRoom" const RoomserverQueryMembershipsForRoomPath = "/roomserver/queryMembershipsForRoom"
// RoomserverQueryInvitesForUserPath is the HTTP path for the QueryInvitesForUser API // RoomserverQueryInvitesForUserPath is the HTTP path for the QueryInvitesForUser API
const RoomserverQueryInvitesForUserPath = "/api/roomserver/queryInvitesForUser" const RoomserverQueryInvitesForUserPath = "/roomserver/queryInvitesForUser"
// RoomserverQueryServerAllowedToSeeEventPath is the HTTP path for the QueryServerAllowedToSeeEvent API // RoomserverQueryServerAllowedToSeeEventPath is the HTTP path for the QueryServerAllowedToSeeEvent API
const RoomserverQueryServerAllowedToSeeEventPath = "/api/roomserver/queryServerAllowedToSeeEvent" const RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent"
// RoomserverQueryMissingEventsPath is the HTTP path for the QueryMissingEvents API // RoomserverQueryMissingEventsPath is the HTTP path for the QueryMissingEvents API
const RoomserverQueryMissingEventsPath = "/api/roomserver/queryMissingEvents" const RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents"
// RoomserverQueryStateAndAuthChainPath is the HTTP path for the QueryStateAndAuthChain API // RoomserverQueryStateAndAuthChainPath is the HTTP path for the QueryStateAndAuthChain API
const RoomserverQueryStateAndAuthChainPath = "/api/roomserver/queryStateAndAuthChain" const RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain"
// RoomserverQueryBackfillPath is the HTTP path for the QueryBackfillPath API // RoomserverQueryBackfillPath is the HTTP path for the QueryBackfillPath API
const RoomserverQueryBackfillPath = "/api/roomserver/queryBackfill" const RoomserverQueryBackfillPath = "/roomserver/queryBackfill"
// RoomserverQueryRoomVersionCapabilitiesPath is the HTTP path for the QueryRoomVersionCapabilities API // RoomserverQueryRoomVersionCapabilitiesPath is the HTTP path for the QueryRoomVersionCapabilities API
const RoomserverQueryRoomVersionCapabilitiesPath = "/api/roomserver/queryRoomVersionCapabilities" const RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities"
// RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API // RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API
const RoomserverQueryRoomVersionForRoomPath = "/api/roomserver/queryRoomVersionForRoom" const RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom"
// QueryLatestEventsAndState implements RoomserverQueryAPI // QueryLatestEventsAndState implements RoomserverQueryAPI
func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState( func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(

View File

@ -6,6 +6,7 @@ import (
"sync" "sync"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"github.com/gorilla/mux"
fsAPI "github.com/matrix-org/dendrite/federationsender/api" fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/caching"
@ -32,8 +33,8 @@ type RoomserverInternalAPI struct {
// SetupHTTP adds the RoomserverInternalAPI handlers to the http.ServeMux. // SetupHTTP adds the RoomserverInternalAPI handlers to the http.ServeMux.
// nolint: gocyclo // nolint: gocyclo
func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { func (r *RoomserverInternalAPI) SetupHTTP(internalAPIMux *mux.Router) {
servMux.Handle(api.RoomserverInputRoomEventsPath, internalAPIMux.Handle(api.RoomserverInputRoomEventsPath,
internal.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
var request api.InputRoomEventsRequest var request api.InputRoomEventsRequest
var response api.InputRoomEventsResponse var response api.InputRoomEventsResponse
@ -46,7 +47,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle(api.RoomserverPerformJoinPath, internalAPIMux.Handle(api.RoomserverPerformJoinPath,
internal.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
var request api.PerformJoinRequest var request api.PerformJoinRequest
var response api.PerformJoinResponse var response api.PerformJoinResponse
@ -59,7 +60,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle(api.RoomserverPerformLeavePath, internalAPIMux.Handle(api.RoomserverPerformLeavePath,
internal.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
var request api.PerformLeaveRequest var request api.PerformLeaveRequest
var response api.PerformLeaveResponse var response api.PerformLeaveResponse
@ -72,7 +73,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryLatestEventsAndStatePath, api.RoomserverQueryLatestEventsAndStatePath,
internal.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
var request api.QueryLatestEventsAndStateRequest var request api.QueryLatestEventsAndStateRequest
@ -86,7 +87,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryStateAfterEventsPath, api.RoomserverQueryStateAfterEventsPath,
internal.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAfterEventsRequest var request api.QueryStateAfterEventsRequest
@ -100,7 +101,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryEventsByIDPath, api.RoomserverQueryEventsByIDPath,
internal.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
var request api.QueryEventsByIDRequest var request api.QueryEventsByIDRequest
@ -114,7 +115,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryMembershipForUserPath, api.RoomserverQueryMembershipForUserPath,
internal.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipForUserRequest var request api.QueryMembershipForUserRequest
@ -128,7 +129,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryMembershipsForRoomPath, api.RoomserverQueryMembershipsForRoomPath,
internal.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipsForRoomRequest var request api.QueryMembershipsForRoomRequest
@ -142,7 +143,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryInvitesForUserPath, api.RoomserverQueryInvitesForUserPath,
internal.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryInvitesForUserRequest var request api.QueryInvitesForUserRequest
@ -156,7 +157,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryServerAllowedToSeeEventPath, api.RoomserverQueryServerAllowedToSeeEventPath,
internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
var request api.QueryServerAllowedToSeeEventRequest var request api.QueryServerAllowedToSeeEventRequest
@ -170,7 +171,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryMissingEventsPath, api.RoomserverQueryMissingEventsPath,
internal.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryMissingEventsRequest var request api.QueryMissingEventsRequest
@ -184,7 +185,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryStateAndAuthChainPath, api.RoomserverQueryStateAndAuthChainPath,
internal.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAndAuthChainRequest var request api.QueryStateAndAuthChainRequest
@ -198,7 +199,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryBackfillPath, api.RoomserverQueryBackfillPath,
internal.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse {
var request api.QueryBackfillRequest var request api.QueryBackfillRequest
@ -212,7 +213,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryRoomVersionCapabilitiesPath, api.RoomserverQueryRoomVersionCapabilitiesPath,
internal.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionCapabilitiesRequest var request api.QueryRoomVersionCapabilitiesRequest
@ -226,7 +227,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverQueryRoomVersionForRoomPath, api.RoomserverQueryRoomVersionForRoomPath,
internal.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionForRoomRequest var request api.QueryRoomVersionForRoomRequest
@ -240,7 +241,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverSetRoomAliasPath, api.RoomserverSetRoomAliasPath,
internal.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
var request api.SetRoomAliasRequest var request api.SetRoomAliasRequest
@ -254,7 +255,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverGetRoomIDForAliasPath, api.RoomserverGetRoomIDForAliasPath,
internal.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
var request api.GetRoomIDForAliasRequest var request api.GetRoomIDForAliasRequest
@ -268,7 +269,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverGetCreatorIDForAliasPath, api.RoomserverGetCreatorIDForAliasPath,
internal.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
var request api.GetCreatorIDForAliasRequest var request api.GetCreatorIDForAliasRequest
@ -282,7 +283,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverGetAliasesForRoomIDPath, api.RoomserverGetAliasesForRoomIDPath,
internal.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
var request api.GetAliasesForRoomIDRequest var request api.GetAliasesForRoomIDRequest
@ -296,7 +297,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
servMux.Handle( internalAPIMux.Handle(
api.RoomserverRemoveRoomAliasPath, api.RoomserverRemoveRoomAliasPath,
internal.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse { internal.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
var request api.RemoveRoomAliasRequest var request api.RemoveRoomAliasRequest

View File

@ -15,8 +15,6 @@
package roomserver package roomserver
import ( import (
"net/http"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
@ -51,9 +49,7 @@ func SetupRoomServerComponent(
KeyRing: keyRing, KeyRing: keyRing,
} }
if base.EnableHTTPAPIs { internalAPI.SetupHTTP(base.InternalAPIMux)
internalAPI.SetupHTTP(http.DefaultServeMux)
}
return &internalAPI return &internalAPI
} }

View File

@ -30,7 +30,7 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
const pathPrefixR0 = "/_matrix/client/r0" const pathPrefixR0 = "/client/r0"
// Setup configures the given mux with sync-server listeners // Setup configures the given mux with sync-server listeners
// //
@ -38,12 +38,12 @@ const pathPrefixR0 = "/_matrix/client/r0"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database, publicAPIMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database,
deviceDB devices.Database, federation *gomatrixserverlib.FederationClient, deviceDB devices.Database, federation *gomatrixserverlib.FederationClient,
rsAPI api.RoomserverInternalAPI, rsAPI api.RoomserverInternalAPI,
cfg *config.Dendrite, cfg *config.Dendrite,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
authData := auth.Data{ authData := auth.Data{
AccountDB: nil, AccountDB: nil,

View File

@ -81,5 +81,5 @@ func SetupSyncAPIComponent(
logrus.WithError(err).Panicf("failed to start typing server consumer") logrus.WithError(err).Panicf("failed to start typing server consumer")
} }
routing.Setup(base.APIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg) routing.Setup(base.PublicAPIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
} }