2024-11-16 05:16:52 +00:00
|
|
|
use std::sync::Arc;
|
2024-11-14 02:50:59 +00:00
|
|
|
use anyhow::Context;
|
2024-11-16 05:16:52 +00:00
|
|
|
use axum::Extension;
|
2024-11-14 02:50:59 +00:00
|
|
|
|
|
|
|
mod config;
|
|
|
|
mod route;
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<std::convert::Infallible> {
|
|
|
|
pretty_env_logger::init();
|
|
|
|
log::debug!("Logging initialized!");
|
2024-11-16 05:16:52 +00:00
|
|
|
|
|
|
|
log::trace!("Creating Minijinja environment...");
|
|
|
|
let mut mj = minijinja::Environment::<'static>::new();
|
|
|
|
|
|
|
|
log::trace!("Adding webfinger page to the Minijinja environment...");
|
2024-11-19 05:06:48 +00:00
|
|
|
mj.add_template("rd.html.j2", include_str!("rd.html.j2"))
|
|
|
|
.expect("rd.html.j2 to be a valid Minijinja template");
|
2024-11-14 02:50:59 +00:00
|
|
|
|
|
|
|
log::trace!("Creating Axum router...");
|
|
|
|
let app = axum::Router::new()
|
2024-11-19 05:06:48 +00:00
|
|
|
.route("/*path", axum::routing::get(route::webfinger_handler))
|
2024-12-12 02:44:08 +00:00
|
|
|
.route("/.healthcheck", axum::routing::get(route::healthcheck_handler))
|
2024-11-16 05:16:52 +00:00
|
|
|
.layer(Extension(Arc::new(mj)));
|
2024-11-14 02:50:59 +00:00
|
|
|
log::trace!("Axum router created successfully!");
|
|
|
|
|
|
|
|
log::trace!("Creating Tokio listener...");
|
2024-12-13 03:37:34 +00:00
|
|
|
let bind_address = config::ACRATE_RDSERVER_BIND_ADDRESS();
|
2024-11-14 02:50:59 +00:00
|
|
|
let listener = tokio::net::TcpListener::bind(bind_address)
|
|
|
|
.await
|
|
|
|
.context("failed to bind listener to address")?;
|
|
|
|
log::trace!("Tokio listener bound to: {bind_address}");
|
|
|
|
|
2024-12-13 03:33:50 +00:00
|
|
|
log::info!("Starting rdserver web server...");
|
2024-11-14 02:50:59 +00:00
|
|
|
axum::serve(listener, app)
|
|
|
|
.await
|
|
|
|
.context("server exited with error")?;
|
|
|
|
|
|
|
|
log::error!("Server exited with no error, panicking.");
|
|
|
|
panic!("server exited with no error");
|
|
|
|
}
|