apub_inbox: Add /.healthcheck route

This commit is contained in:
Steffo 2024-12-16 02:32:19 +01:00
parent f1fd63d13a
commit e72fa092fb
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 15 additions and 0 deletions

View file

@ -16,6 +16,7 @@ async fn main() -> anyhow::Result<std::convert::Infallible> {
log::trace!("Creating Axum router..."); log::trace!("Creating Axum router...");
let app = axum::Router::new() let app = axum::Router::new()
.route("/.healthcheck", axum::routing::get(route::healthcheck_handler))
.layer(Extension(Arc::new(mj))); .layer(Extension(Arc::new(mj)));
log::trace!("Axum router created successfully!"); log::trace!("Axum router created successfully!");

View file

@ -0,0 +1,14 @@
use axum::http::StatusCode;
use acrate_database::connect::connect_async;
pub async fn healthcheck_handler() -> Result<StatusCode, StatusCode> {
log::debug!("Handling an healthcheck request!");
log::trace!("Making sure the database is up...");
let _conn = connect_async()
.await
.map_err(|_| StatusCode::BAD_GATEWAY)?;
log::trace!("Healthcheck successful! Everything's fine!");
Ok(StatusCode::NO_CONTENT)
}