diff --git a/acrate_apub_inbox/Cargo.toml b/acrate_apub_inbox/Cargo.toml index 526c49f..61b9db5 100644 --- a/acrate_apub_inbox/Cargo.toml +++ b/acrate_apub_inbox/Cargo.toml @@ -11,6 +11,7 @@ categories = ["web-programming"] [dependencies] acrate_database = { path = "../acrate_database", features = ["connect"] } +acrate_utils = { path = "../acrate_utils" } anyhow = "1.0.93" axum = { version = "0.7.7", features = ["macros"] } log = { version = "0.4.22", features = ["std", "max_level_trace", "release_max_level_debug"] } diff --git a/acrate_apub_inbox/src/config.rs b/acrate_apub_inbox/src/config.rs index b346973..0a46520 100644 --- a/acrate_apub_inbox/src/config.rs +++ b/acrate_apub_inbox/src/config.rs @@ -1,3 +1,3 @@ micronfig::config!( - ACRATE_APUB_INBOX_BIND_ADDRESS: String, + ACRATE_APUB_INBOX_BIND_ADDRESS: String > std::net::SocketAddr, ); diff --git a/acrate_apub_inbox/src/main.rs b/acrate_apub_inbox/src/main.rs index 9c835ef..2fd6e9f 100644 --- a/acrate_apub_inbox/src/main.rs +++ b/acrate_apub_inbox/src/main.rs @@ -1,38 +1,18 @@ -use std::sync::Arc; -use anyhow::Context; -use axum::Extension; +use axum::routing::{get, post}; +use acrate_utils::web_server; mod config; mod route; #[tokio::main] -async fn main() -> anyhow::Result { - pretty_env_logger::init(); - log::debug!("Logging initialized!"); - - log::trace!("Creating Minijinja environment..."); - let mut mj = minijinja::Environment::<'static>::new(); - - log::trace!("Creating Axum router..."); - let app = axum::Router::new() - .route("/inbox", axum::routing::post(route::inbox_handler)) - .route("/.healthcheck", axum::routing::get(route::healthcheck_handler)) - .layer(Extension(Arc::new(mj))); - log::trace!("Axum router created successfully!"); - - log::trace!("Creating Tokio listener..."); - let bind_address = config::ACRATE_APUB_INBOX_BIND_ADDRESS(); - let listener = tokio::net::TcpListener::bind(bind_address) - .await - .context("failed to bind listener to address")?; - log::trace!("Tokio listener bound to: {bind_address}"); - - log::info!("Starting apub_inbox web server..."); - axum::serve(listener, app) - .await - .context("server exited with error")?; - - log::error!("Server exited with no error, panicking."); - panic!("server exited with no error"); +async fn main() { + web_server!( + on: *config::ACRATE_APUB_INBOX_BIND_ADDRESS(), + templates: [ ], + routes: { + "/inbox" => post(route::inbox_handler), + "/.healthcheck" => get(route::healthcheck_handler) + } + ); }