From bd1dd89f78d5022e116036d882ac6a9373f787bb Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Fri, 15 May 2026 11:47:37 +0200 Subject: [PATCH] refactor(bootstrap): use ap_service.router() as single source of truth for AP routes --- .../adapters/activitypub-base/src/service.rs | 8 +++- crates/bootstrap/src/main.rs | 38 +------------------ 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/crates/adapters/activitypub-base/src/service.rs b/crates/adapters/activitypub-base/src/service.rs index 8efde5d..3e1fe6f 100644 --- a/crates/adapters/activitypub-base/src/service.rs +++ b/crates/adapters/activitypub-base/src/service.rs @@ -261,7 +261,13 @@ impl ActivityPubService { Ok(serde_json::to_string(&WithContext::new_default(person))?) } - pub fn router(&self) -> Router { + /// Returns the ActivityPub router compatible with any outer state `S`. + /// Handlers only use `Data` injected by the middleware layer, + /// so the router is independent of the application state type. + pub fn router(&self) -> Router + where + S: Clone + Send + Sync + 'static, + { Router::new() .route("/.well-known/nodeinfo", get(nodeinfo_well_known_handler)) .route("/nodeinfo/2.0", get(nodeinfo_handler)) diff --git a/crates/bootstrap/src/main.rs b/crates/bootstrap/src/main.rs index b9e4ffc..44a8958 100644 --- a/crates/bootstrap/src/main.rs +++ b/crates/bootstrap/src/main.rs @@ -32,44 +32,8 @@ async fn main() { .allow_headers(tower_http::cors::Any) }; - use activitypub_base::{ - followers_handler::{followers_handler, following_handler}, - inbox::inbox_handler, - nodeinfo::{nodeinfo_handler, nodeinfo_well_known_handler}, - outbox::outbox_handler, - webfinger::webfinger_handler, - }; - let ap_router = axum::Router::new() - .route( - "/.well-known/webfinger", - axum::routing::get(webfinger_handler), - ) - .route( - "/.well-known/nodeinfo", - axum::routing::get(nodeinfo_well_known_handler), - ) - .route("/nodeinfo/2.0", axum::routing::get(nodeinfo_handler)) - .route("/inbox", axum::routing::post(inbox_handler)) - .route( - "/users/{username}/inbox", - axum::routing::post(inbox_handler), - ) - .route( - "/users/{username}/outbox", - axum::routing::get(outbox_handler), - ) - .route( - "/users/{username}/followers", - axum::routing::get(followers_handler), - ) - .route( - "/users/{username}/following", - axum::routing::get(following_handler), - ) - .layer(infra.ap_service.federation_config().middleware()); - let base = presentation::routes::router() - .merge(ap_router) + .merge(infra.ap_service.router::()) .with_state(infra.state) .layer(cors);