Added .well-known/matrix/server endpoint (#1988)

* Added .well-known/matrix/server endpoint

Signed-off-by: Ryan Whittington <twentybitdev@gmail.com>

* Replaced tabs with spaces

Signed-off-by: Ryan Whittington <twentybitdev@gmail.com>
This commit is contained in:
Ryan W 2021-09-10 10:05:31 +01:00 committed by GitHub
parent a624eab309
commit 1cd4d50181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 46 additions and 7 deletions

View file

@ -30,6 +30,7 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
// Setup registers HTTP handlers with the given ServeMux.
@ -41,7 +42,7 @@ import (
// applied:
// nolint: gocyclo
func Setup(
fedMux, keyMux *mux.Router,
fedMux, keyMux, wkMux *mux.Router,
cfg *config.FederationAPI,
rsAPI roomserverAPI.RoomserverInternalAPI,
eduAPI eduserverAPI.EDUServerInputAPI,
@ -85,6 +86,21 @@ func Setup(
return NotaryKeys(req, cfg, fsAPI, pkReq)
})
if cfg.Matrix.WellKnownServerName != "" {
logrus.Infof("Setting m.server as %s at /.well-known/matrix/server", cfg.Matrix.WellKnownServerName)
wkMux.Handle("/server", httputil.MakeExternalAPI("wellknown", func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
ServerName string `json:"m.server"`
}{
ServerName: cfg.Matrix.WellKnownServerName,
},
}
}),
).Methods(http.MethodGet, http.MethodOptions)
}
// Ignore the {keyID} argument as we only have a single server key so we always
// return that key.
// Even if we had more than one server key, we would probably still ignore the