summaryrefslogtreecommitdiff
path: root/src/wellknown.rs
blob: 9c9bc1c0cda99b1df64784a0764d62e18ed87681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use rocket::{
    get,
    http::Header,
    response::{self, Responder},
    serde::json::{json, Value},
    Request,
};

pub struct Cors<T>(pub T);

#[rocket::async_trait]
impl<'r, T: Responder<'r, 'static>> Responder<'r, 'static> for Cors<T> {
    fn respond_to(self, request: &'r Request<'_>) -> response::Result<'static> {
        let mut resp = self.0.respond_to(request);
        if let Ok(resp) = &mut resp {
            resp.set_header(Header::new("access-control-allow-origin", "*"));
        }
        resp
    }
}

#[get("/.well-known/matrix/client")]
pub fn r_wellknown_matrix_client() -> Cors<Value> {
    Cors(json!({"m.homeserver": {"base_url": "https://matrix.metamuffin.org"}} ))
}

#[get("/.well-known/matrix/server")]
pub fn r_wellknown_matrix_server() -> Cors<Value> {
    Cors(json!({"m.server": "matrix.metamuffin.org:443"} ))
}

#[get("/.well-known/security.txt")]
pub fn r_wellknown_security() -> &'static str {
    r#"# In can case you found a security vulnerability in my services and want to disclose them privately, use the information below.
Contact: https://metamuffin.org/contact
Encryption: https://metamuffin.org/key.asc
    "#
}