Skip to main content

tuwunel_api/server/
well_known.rs

1use axum::extract::State;
2use ruma::api::{error::ErrorKind, federation::discovery::discover_homeserver};
3use tuwunel_core::{Error, Result};
4
5use crate::Ruma;
6
7/// # `GET /.well-known/matrix/server`
8///
9/// Returns the .well-known URL if it is configured, otherwise returns 404.
10pub(crate) async fn well_known_server(
11	State(services): State<crate::State>,
12	_body: Ruma<discover_homeserver::Request>,
13) -> Result<discover_homeserver::Response> {
14	Ok(discover_homeserver::Response {
15		server: match services.server.config.well_known.server.as_ref() {
16			| Some(server_name) => server_name.to_owned(),
17			| None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
18		},
19	})
20}