rdserver: Add .healthcheck route for monitoring purposes

This commit is contained in:
Steffo 2024-12-12 03:44:08 +01:00
parent d3126f8e2e
commit 0ac7a04477
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 12 additions and 0 deletions

View file

@ -21,6 +21,7 @@ async fn main() -> anyhow::Result<std::convert::Infallible> {
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!");

View file

@ -13,6 +13,17 @@ use acrate_rd::jrd::ResourceDescriptorLinkJRD;
use acrate_rd::xrd::{ResourceDescriptorLinkXRD, ResourceDescriptorPropertyXRD, ResourceDescriptorTitleXRD};
use crate::config;
pub async fn healthcheck_handler() -> Result<StatusCode, StatusCode> {
log::info!("Handling an healthcheck request!");
log::trace!("Making sure the database is up...");
let _conn = AsyncPgConnection::establish(config::ACRATE_WEBFINGER_DATABASE_URL())
.await
.map_err(|_| StatusCode::BAD_GATEWAY)?;
Ok(StatusCode::NO_CONTENT)
}
#[derive(Debug, Clone, Deserialize)]
pub struct WebfingerQuery {
pub resource: Option<String>,