diff --git a/build/gobind/monolith.go b/build/gobind/monolith.go index e43734900..a4803396f 100644 --- a/build/gobind/monolith.go +++ b/build/gobind/monolith.go @@ -18,7 +18,6 @@ import ( "github.com/matrix-org/dendrite/federationsender" "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal/config" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" "github.com/matrix-org/dendrite/keyserver" "github.com/matrix-org/dendrite/roomserver" @@ -172,14 +171,6 @@ func (m *DendriteMonolith) Start() { } monolith.AddAllPublicRoutes(base.PublicAPIMux) - httputil.SetupHTTPAPI( - base.BaseMux, - base.PublicAPIMux, - base.InternalAPIMux, - &cfg.Global, - base.UseHTTPAPIs, - ) - // Build both ends of a HTTP multiplex. m.httpServer = &http.Server{ Addr: ":0", @@ -190,7 +181,7 @@ func (m *DendriteMonolith) Start() { BaseContext: func(_ net.Listener) context.Context { return context.Background() }, - Handler: base.BaseMux, + Handler: base.PublicAPIMux, } go func() { diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index e30355476..5379a7cd8 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -31,7 +31,6 @@ import ( "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/federationsender" "github.com/matrix-org/dendrite/internal/config" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" "github.com/matrix-org/dendrite/keyserver" "github.com/matrix-org/dendrite/roomserver" @@ -192,19 +191,11 @@ func main() { } monolith.AddAllPublicRoutes(base.Base.PublicAPIMux) - httputil.SetupHTTPAPI( - base.Base.BaseMux, - base.Base.PublicAPIMux, - base.Base.InternalAPIMux, - &cfg.Global, - base.Base.UseHTTPAPIs, - ) - // Expose the matrix APIs directly rather than putting them under a /api path. go func() { httpBindAddr := fmt.Sprintf(":%d", *instancePort) logrus.Info("Listening on ", httpBindAddr) - logrus.Fatal(http.ListenAndServe(httpBindAddr, base.Base.BaseMux)) + logrus.Fatal(http.ListenAndServe(httpBindAddr, base.Base.PublicAPIMux)) }() // Expose the matrix APIs also via libp2p if base.LibP2P != nil { @@ -217,7 +208,7 @@ func main() { defer func() { logrus.Fatal(listener.Close()) }() - logrus.Fatal(http.Serve(listener, base.Base.BaseMux)) + logrus.Fatal(http.Serve(listener, base.Base.PublicAPIMux)) }() } diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 33ed15429..1014912ca 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -35,7 +35,6 @@ import ( "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/config" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" "github.com/matrix-org/dendrite/keyserver" "github.com/matrix-org/dendrite/roomserver" @@ -132,7 +131,7 @@ func main() { rsComponent.SetFederationSenderAPI(fsAPI) - embed.Embed(base.BaseMux, *instancePort, "Yggdrasil Demo") + embed.Embed(base.PublicAPIMux, *instancePort, "Yggdrasil Demo") monolith := setup.Monolith{ Config: base.Cfg, @@ -157,14 +156,6 @@ func main() { } monolith.AddAllPublicRoutes(base.PublicAPIMux) - httputil.SetupHTTPAPI( - base.BaseMux, - base.PublicAPIMux, - base.InternalAPIMux, - &cfg.Global, - base.UseHTTPAPIs, - ) - // Build both ends of a HTTP multiplex. httpServer := &http.Server{ Addr: ":0", @@ -175,7 +166,7 @@ func main() { BaseContext: func(_ net.Listener) context.Context { return context.Background() }, - Handler: base.BaseMux, + Handler: base.PublicAPIMux, } go func() { @@ -185,7 +176,7 @@ func main() { go func() { httpBindAddr := fmt.Sprintf(":%d", *instancePort) logrus.Info("Listening on ", httpBindAddr) - logrus.Fatal(http.ListenAndServe(httpBindAddr, base.BaseMux)) + logrus.Fatal(http.ListenAndServe(httpBindAddr, base.PublicAPIMux)) }() go func() { logrus.Info("Sending wake-up message to known nodes") diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index f350a938b..70abcb4ba 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -21,6 +21,7 @@ import ( "fmt" "syscall/js" + "github.com/gorilla/mux" "github.com/matrix-org/dendrite/appservice" "github.com/matrix-org/dendrite/currentstateserver" "github.com/matrix-org/dendrite/eduserver" @@ -236,20 +237,16 @@ func main() { } monolith.AddAllPublicRoutes(base.PublicAPIMux) - httputil.SetupHTTPAPI( - base.BaseMux, - base.PublicAPIMux, - base.InternalAPIMux, - &cfg.Global, - base.UseHTTPAPIs, - ) + router := mux.NewRouter() + router.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux) + router.PathPrefix(httputil.PublicPathPrefix).Handler(base.PublicAPIMux) // Expose the matrix APIs via libp2p-js - for federation traffic if node != nil { go func() { logrus.Info("Listening on libp2p-js host ID ", node.Id) s := JSServer{ - Mux: base.BaseMux, + Mux: base.PublicAPIMux, } s.ListenAndServe("p2p") }() @@ -259,7 +256,7 @@ func main() { go func() { logrus.Info("Listening for service-worker fetch traffic") s := JSServer{ - Mux: base.BaseMux, + Mux: router, } s.ListenAndServe("fetch") }() diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index 331d33294..e73dcd29e 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -8,7 +8,6 @@ import ( "github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/internal/config" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/gomatrix" @@ -33,14 +32,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { // TODO: This is pretty fragile, as if anything calls anything on these nils this test will break. // Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing. federationapi.AddPublicRoutes(base.PublicAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, nil) - httputil.SetupHTTPAPI( - base.BaseMux, - base.PublicAPIMux, - base.InternalAPIMux, - &cfg.Global, - base.UseHTTPAPIs, - ) - baseURL, cancel := test.ListenAndServe(t, base.BaseMux, true) + baseURL, cancel := test.ListenAndServe(t, base.PublicAPIMux, true) defer cancel() serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://")) diff --git a/internal/httputil/paths.go b/internal/httputil/paths.go index 965abd306..728b5a871 100644 --- a/internal/httputil/paths.go +++ b/internal/httputil/paths.go @@ -15,6 +15,6 @@ package httputil const ( - PublicPathPrefix = "/_matrix" - InternalPathPrefix = "/api" + PublicPathPrefix = "/_matrix/" + InternalPathPrefix = "/api/" )