Skip to main content

tuwunel_api/client/
well_known.rs

1use axum::extract::State;
2use ruma::api::client::discovery::{
3	discover_homeserver::{self, HomeserverInfo},
4	discover_support::{self},
5};
6use tuwunel_core::{Err, Result};
7
8use crate::Ruma;
9
10/// # `GET /.well-known/matrix/client`
11///
12/// Returns the .well-known URL if it is configured, otherwise returns 404.
13/// Also includes RTC transport configuration for Element Call (MSC4143).
14pub(crate) async fn well_known_client(
15	State(services): State<crate::State>,
16	_body: Ruma<discover_homeserver::Request>,
17) -> Result<discover_homeserver::Response> {
18	let homeserver = HomeserverInfo {
19		base_url: match services.config.well_known.client.as_ref() {
20			| Some(url) => url.to_string(),
21			| None => return Err!(Request(NotFound("Not found."))),
22		},
23	};
24
25	let rtc_foci = services.config.well_known.get_transports()?;
26
27	Ok(discover_homeserver::Response {
28		rtc_foci,
29		..discover_homeserver::Response::new(homeserver)
30	})
31}
32
33/// # `GET /.well-known/matrix/support`
34///
35/// Server support contact and support page of a homeserver's domain.
36pub(crate) async fn well_known_support(
37	State(services): State<crate::State>,
38	_body: Ruma<discover_support::Request>,
39) -> Result<discover_support::Response> {
40	let config = &services.config.well_known;
41
42	let support_page = config
43		.support_page
44		.as_ref()
45		.map(ToString::to_string);
46
47	let contacts = config.get_contacts();
48
49	let policies = config.get_policies();
50
51	if support_page.is_none() && contacts.is_empty() && policies.is_empty() {
52		return Err!(Request(NotFound("Not found.")));
53	}
54
55	Ok(discover_support::Response { contacts, support_page, policies })
56}