add support for serving client+server well-known and /client/server.json
endpoints from conduwuit
the last endpoint is a non-standard health check endpoint used by at least Element Web as a weird way to determine if syncv3 is available there can also be some valid use-cases for serving well-knowns from the application itself Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
bb2f213ac3
commit
8586b15e1a
5 changed files with 49 additions and 17 deletions
|
@ -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"))
|
||||
})))
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue