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!("Adding webfinger page to the Minijinja environment..."); mj.add_template("rd.html.j2", include_str!("rd.html.j2")) .expect("rd.html.j2 to be a valid Minijinja template"); log::trace!("Creating Axum router..."); let app = axum::Router::new() .route("/*path", axum::routing::get(route::webfinger_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_RDSERVER_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 rdserver 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"); }