Add configuration option for sliding sync when hosting /.well-known/matrix/client

This commit is contained in:
Devon Hudson 2023-08-24 13:52:31 -06:00
parent a721294e2b
commit be51801788
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
2 changed files with 46 additions and 14 deletions

View file

@ -96,22 +96,50 @@ func Setup(
if cfg.Matrix.WellKnownClientName != "" {
logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName)
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
HomeserverName struct {
BaseUrl string `json:"base_url"`
} `json:"m.homeserver"`
}{
HomeserverName: struct {
BaseUrl string `json:"base_url"`
if cfg.Matrix.WellKnownSlidingSyncProxy != "" {
logrus.Infof("Setting org.matrix.msc3575.proxy url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownSlidingSyncProxy)
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
HomeserverName struct {
BaseUrl string `json:"base_url"`
} `json:"m.homeserver"`
SlidingSyncProxy struct {
Url string `json:"url"`
} `json:"org.matrix.msc3575.proxy"`
}{
BaseUrl: cfg.Matrix.WellKnownClientName,
HomeserverName: struct {
BaseUrl string `json:"base_url"`
}{
BaseUrl: cfg.Matrix.WellKnownClientName,
},
SlidingSyncProxy: struct {
Url string `json:"url"`
}{
Url: cfg.Matrix.WellKnownSlidingSyncProxy,
},
},
},
}
})).Methods(http.MethodGet, http.MethodOptions)
}
})).Methods(http.MethodGet, http.MethodOptions)
} else {
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
HomeserverName struct {
BaseUrl string `json:"base_url"`
} `json:"m.homeserver"`
}{
HomeserverName: struct {
BaseUrl string `json:"base_url"`
}{
BaseUrl: cfg.Matrix.WellKnownClientName,
},
},
}
})).Methods(http.MethodGet, http.MethodOptions)
}
}
publicAPIMux.Handle("/versions",

View file

@ -48,6 +48,10 @@ type Global struct {
// The server name to delegate client-server communications to, with optional port
WellKnownClientName string `yaml:"well_known_client_name"`
// The server name to delegate sliding sync communications to, with optional port.
// Requires `well_known_client_name` to also be configured.
WellKnownSlidingSyncProxy string `yaml:"well_known_sliding_sync_proxy"`
// Disables federation. Dendrite will not be able to make any outbound HTTP requests
// to other servers and the federation API will not be exposed.
DisableFederation bool `yaml:"disable_federation"`