diff --git a/acrate_apub_inbox/src/config.rs b/acrate_apub_inbox/src/config.rs new file mode 100644 index 0000000..b346973 --- /dev/null +++ b/acrate_apub_inbox/src/config.rs @@ -0,0 +1,3 @@ +micronfig::config!( + ACRATE_APUB_INBOX_BIND_ADDRESS: String, +); diff --git a/acrate_apub_inbox/src/main.rs b/acrate_apub_inbox/src/main.rs index e7a11a9..26dd56f 100644 --- a/acrate_apub_inbox/src/main.rs +++ b/acrate_apub_inbox/src/main.rs @@ -1,3 +1,36 @@ -fn main() { - println!("Hello, world!"); +use std::sync::Arc; +use anyhow::Context; +use axum::Extension; + +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() + .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"); } diff --git a/acrate_apub_inbox/src/route.rs b/acrate_apub_inbox/src/route.rs new file mode 100644 index 0000000..e69de29