diff --git a/src/api/client_server/unversioned.rs b/src/api/client_server/unversioned.rs index e78ad1fa..49cb7bf5 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, -) -> Result { +pub async fn well_known_client_route() -> Result { 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 { + 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 5c1ce83b..7a993365 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 { + 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 38458860..732e10fe 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, + pub well_known_server: Option, #[serde(default)] pub allow_jaeger: bool, #[serde(default)] diff --git a/src/main.rs b/src/main.rs index 15c045c1..2ac0f1fd 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(self, handler: H) -> Self where diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 05020980..bf8b3dfb 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -509,6 +509,10 @@ impl Service<'_> { &self.config.well_known_client } + pub fn well_known_server(&self) -> &Option { + &self.config.well_known_server + } + pub fn unix_socket_path(&self) -> &Option { &self.config.unix_socket_path }