apub_inbox: Use web_server! macro

This commit is contained in:
Steffo 2024-12-18 16:57:24 +01:00
parent 5b62ff6ff7
commit c972fbff31
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 13 additions and 32 deletions

View file

@ -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"] }

View file

@ -1,3 +1,3 @@
micronfig::config!(
ACRATE_APUB_INBOX_BIND_ADDRESS: String,
ACRATE_APUB_INBOX_BIND_ADDRESS: String > std::net::SocketAddr,
);

View file

@ -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<std::convert::Infallible> {
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)
}
);
}