diff --git a/src/api/client_server/unversioned.rs b/src/api/client_server/unversioned.rs index e78ad1fa94febfdd1384108932d6b01f58f65c53..49cb7bf5e2cc619ae1af0f571f93cd258ef28388 100644 --- a/src/api/client_server/unversioned.rs +++ b/src/api/client_server/unversioned.rs @@ -45,9 +45,7 @@ pub async fn get_supported_versions_route( } /// # `GET /.well-known/matrix/client` -pub async fn well_known_client_route( - _body: Ruma<get_supported_versions::Request>, -) -> Result<impl IntoResponse> { +pub async fn well_known_client_route() -> Result<impl IntoResponse> { let client_url = match services().globals.well_known_client() { Some(url) => url.clone(), None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), @@ -58,3 +56,22 @@ pub async fn well_known_client_route( "org.matrix.msc3575.proxy": {"url": client_url} }))) } + +/// # `GET /client/server.json` +/// +/// Endpoint provided by sliding sync proxy used by some clients such as Element Web +/// as a non-standard health check. +pub async fn syncv3_client_server_json() -> Result<impl IntoResponse> { + let server_url = match services().globals.well_known_client() { + Some(url) => url.clone(), + None => match services().globals.well_known_server() { + Some(url) => url.clone(), + None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), + }, + }; + + Ok(Json(serde_json::json!({ + "server": server_url, + "version": format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")) + }))) +} diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 5c1ce83b55d481444856df70992ec7bcfc47d4a2..7a993365db579783bbf4618c3be12b41ae12a3a5 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -2060,6 +2060,18 @@ pub async fn claim_keys_route( }) } +/// # `GET /.well-known/matrix/server` +pub async fn well_known_server_route() -> Result<impl IntoResponse> { + let server_url = match services().globals.well_known_server() { + Some(url) => url.clone(), + None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), + }; + + Ok(Json(serde_json::json!({ + "m.server": server_url + }))) +} + #[cfg(test)] mod tests { use super::{add_port_to_hostname, get_ip_with_port, FedDest}; diff --git a/src/config/mod.rs b/src/config/mod.rs index 384588605510810c016c36e41d5891c7d1752124..732e10fea306e8eea02cfd463ca74faddc8bf8f6 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -70,6 +70,7 @@ pub struct Config { #[serde(default = "default_default_room_version")] pub default_room_version: RoomVersionId, pub well_known_client: Option<String>, + pub well_known_server: Option<String>, #[serde(default)] pub allow_jaeger: bool, #[serde(default)] diff --git a/src/main.rs b/src/main.rs index 15c045c1640c5a0ab8101e1a51165443639582d8..2ac0f1fd11f442095c5bbf8bfbbe3f1ff6e3f4aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -514,7 +514,18 @@ fn routes() -> Router { "/_matrix/client/v3/rooms/:room_id/initialSync", get(initial_sync), ) - //.route("/client/server.json", get(syncv3_client_server_json)) + .route( + "/client/server.json", + get(client_server::syncv3_client_server_json), + ) + .route( + "/.well-known/matrix/client", + get(client_server::well_known_client_route), + ) + .route( + "/.well-known/matrix/server", + get(server_server::well_known_server_route), + ) .route("/", get(it_works)) .fallback(not_found) } @@ -572,19 +583,6 @@ async fn it_works() -> &'static str { "hewwo from conduwuit woof!" } -/* -// TODO: add /client/server.json support by querying our client well-known for the true matrix homeserver URL -async fn syncv3_client_server_json(uri: Uri) -> impl IntoResponse { - let server_name = services().globals.server_name().to_string(); - let response = services().globals.default_client().get(&format!("https://{server_name")) - let server = uri.scheme_str().unwrap_or("https").to_owned() + "://" + uri.host().unwrap(); - let version = format!("cowonduit {}", env!("CARGO_PKG_VERSION").to_owned()); - let body = format!("{{\"server\":\"{server}\",\"version\":\"{version}\"}}"); - - Json(body) -} -*/ - trait RouterExt { fn ruma_route<H, T>(self, handler: H) -> Self where diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 0502098098c035e28f8f7bd01073aac1f1b63680..bf8b3dfbe47dbca790c56ff1f9ad87ef2d71b3d1 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -509,6 +509,10 @@ pub fn well_known_client(&self) -> &Option<String> { &self.config.well_known_client } + pub fn well_known_server(&self) -> &Option<String> { + &self.config.well_known_server + } + pub fn unix_socket_path(&self) -> &Option<PathBuf> { &self.config.unix_socket_path }