about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1cc01c2..2d15423 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -206,3 +206,52 @@ pub mod companion {
             )
     }
 }
+
+async fn teapot_route() -> impl axum::response::IntoResponse {
+    use axum::http::{header, StatusCode};
+    (StatusCode::IM_A_TEAPOT, [(header::CONTENT_TYPE, "text/plain")], "Sorry, can't brew coffee yet!")
+}
+
+async fn health_check<D>(
+    axum::extract::State(data): axum::extract::State<D>,
+) -> impl axum::response::IntoResponse
+where
+    D: crate::database::Storage
+{
+    (axum::http::StatusCode::OK, std::borrow::Cow::Borrowed("OK"))
+}
+
+pub async fn compose_kittybox<St, A, S, M, Q>() -> axum::Router<St>
+where
+A: AuthBackend + 'static + FromRef<St>,
+S: Storage + 'static + FromRef<St>,
+M: MediaStore + 'static + FromRef<St>,
+Q: kittybox_util::queue::JobQueue<crate::webmentions::Webmention> + FromRef<St>,
+reqwest::Client: FromRef<St>,
+Arc<Mutex<JoinSet<()>>>: FromRef<St>,
+St: Clone + Send + Sync + 'static
+{
+    use axum::routing::get;
+    axum::Router::new()
+        .route("/", get(crate::frontend::homepage::<S>))
+        .fallback(get(crate::frontend::catchall::<S>))
+        .route("/.kittybox/micropub", crate::micropub::router::<A, S, St>())
+        .route("/.kittybox/onboarding", crate::frontend::onboarding::router::<St, S>())
+        .nest("/.kittybox/media", crate::media::router::<St, A, M>())
+        .merge(crate::indieauth::router::<St, A, S>())
+        .merge(crate::webmentions::router::<St, Q>())
+        .route("/.kittybox/health", get(health_check::<S>))
+        .route(
+            "/.kittybox/static/:path",
+            axum::routing::get(crate::frontend::statics)
+        )
+        .route("/.kittybox/coffee", get(teapot_route))
+        .nest("/.kittybox/micropub/client", crate::companion::router::<St>())
+        .layer(tower_http::trace::TraceLayer::new_for_http())
+        .layer(tower_http::catch_panic::CatchPanicLayer::new())
+        .layer(tower_http::sensitive_headers::SetSensitiveHeadersLayer::new([
+            axum::http::header::AUTHORIZATION,
+            axum::http::header::COOKIE,
+            axum::http::header::SET_COOKIE,
+        ]))
+}