Try something different

This commit is contained in:
Neil Alexander 2021-07-27 20:06:43 +01:00
parent 71e2ae7421
commit 02699bf704
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -29,6 +29,13 @@ import (
"github.com/matrix-org/util"
)
func unstableDefaultMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, "/unstable/", "/r0/", 1)
next.ServeHTTP(w, r)
})
}
// Setup configures the given mux with sync-server listeners
//
// Due to Setup being used to call many other functions, a gocyclo nolint is
@ -42,10 +49,8 @@ func Setup(
) {
r0mux := csMux.PathPrefix("/r0").Subrouter()
unstableMux := csMux.PathPrefix("/unstable").Subrouter()
defer unstableMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, "/unstable/", "/r0/", 1)
r0mux.ServeHTTP(w, r)
}) // serve r0 endpoints by default unless overridden
unstableMux.NotFoundHandler = r0mux
unstableMux.Use(unstableDefaultMiddleware)
// TODO: Add AS support for all handlers below.
r0mux.Handle("/sync", httputil.MakeAuthAPI("sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {