]> Untitled Git - lemmy.git/blob - src/routes/federation.rs
Isomorphic docker (#1124)
[lemmy.git] / src / routes / federation.rs
1 use crate::apub::{
2   comment::get_apub_comment,
3   community::*,
4   inbox::{community_inbox::community_inbox, shared_inbox::shared_inbox, user_inbox::user_inbox},
5   post::get_apub_post,
6   user::*,
7   APUB_JSON_CONTENT_TYPE,
8 };
9 use actix_web::*;
10 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
11 use lemmy_utils::settings::Settings;
12 use sha2::{Digest, Sha256};
13
14 pub fn config(cfg: &mut web::ServiceConfig) {
15   if Settings::get().federation.enabled {
16     println!("federation enabled, host is {}", Settings::get().hostname);
17     let digest_verifier = VerifyDigest::new(Sha256::new());
18
19     cfg
20       .service(
21         web::scope("/")
22           .guard(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
23           .route(
24             "/c/{community_name}",
25             web::get().to(get_apub_community_http),
26           )
27           .route(
28             "/c/{community_name}/followers",
29             web::get().to(get_apub_community_followers),
30           )
31           .route(
32             "/c/{community_name}/outbox",
33             web::get().to(get_apub_community_outbox),
34           )
35           .route("/u/{user_name}", web::get().to(get_apub_user_http))
36           .route("/post/{post_id}", web::get().to(get_apub_post))
37           .route("/comment/{comment_id}", web::get().to(get_apub_comment)),
38       )
39       // Inboxes dont work with the header guard for some reason.
40       .service(
41         web::resource("/c/{community_name}/inbox")
42           .wrap(digest_verifier.clone())
43           .route(web::post().to(community_inbox)),
44       )
45       .service(
46         web::resource("/u/{user_name}/inbox")
47           .wrap(digest_verifier.clone())
48           .route(web::post().to(user_inbox)),
49       )
50       .service(
51         web::resource("/inbox")
52           .wrap(digest_verifier)
53           .route(web::post().to(shared_inbox)),
54       );
55   }
56 }