2 comment::get_apub_comment,
5 get_apub_community_followers,
6 get_apub_community_http,
7 get_apub_community_moderators,
8 get_apub_community_outbox,
11 person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
16 guard::{Guard, GuardContext},
17 http::{header, Method},
20 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
21 use lemmy_utils::settings::structs::Settings;
22 use sha2::{Digest, Sha256};
24 pub fn config(cfg: &mut web::ServiceConfig, settings: &Settings) {
25 if settings.federation.enabled {
26 println!("federation enabled, host is {}", settings.hostname);
30 "/c/{community_name}",
31 web::get().to(get_apub_community_http),
34 "/c/{community_name}/followers",
35 web::get().to(get_apub_community_followers),
38 "/c/{community_name}/outbox",
39 web::get().to(get_apub_community_outbox),
42 "/c/{community_name}/moderators",
43 web::get().to(get_apub_community_moderators),
45 .route("/u/{user_name}", web::get().to(get_apub_person_http))
47 "/u/{user_name}/outbox",
48 web::get().to(get_apub_person_outbox),
50 .route("/post/{post_id}", web::get().to(get_apub_post))
51 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
52 .route("/activities/{type_}/{id}", web::get().to(get_activity));
56 .wrap(VerifyDigest::new(Sha256::new()))
57 .guard(InboxRequestGuard)
58 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
59 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
60 .route("/inbox", web::post().to(shared_inbox)),
65 /// Without this, things like webfinger or RSS feeds stop working, as all requests seem to get
66 /// routed into the inbox service (because it covers the root path). So we filter out anything that
67 /// definitely can't be an inbox request (based on Accept header and request method).
68 struct InboxRequestGuard;
70 impl Guard for InboxRequestGuard {
71 fn check(&self, ctx: &GuardContext) -> bool {
72 if ctx.head().method != Method::POST {
75 if let Some(val) = ctx.head().headers.get(header::CONTENT_TYPE) {
76 return val.as_bytes().starts_with(b"application/");