Create health check endpoint

This commit is contained in:
2025-05-03 05:30:34 +00:00
parent a82da927b0
commit 6bb6322aa4
2 changed files with 24 additions and 0 deletions

23
src/api/health.rs Normal file
View File

@ -0,0 +1,23 @@
use leptos::prelude::*;
use crate::util::serverfn_client::Client;
#[server(endpoint = "health", client = Client)]
pub async fn health() -> Result<String, ServerFnError> {
use crate::util::database::get_db_conn;
use crate::util::redis::get_redis_conn;
use diesel::connection::SimpleConnection;
use server_fn::error::NoCustomError;
use tower_sessions_redis_store::fred::interfaces::ClientLike;
get_db_conn()
.batch_execute("SELECT 1")
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Database error: {e}")))?;
get_redis_conn()
.ping::<()>(None)
.await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Redis error: {e}")))?;
Ok("ok".to_string())
}

View File

@ -2,6 +2,7 @@ pub mod album;
pub mod albums;
pub mod artists;
pub mod auth;
pub mod health;
pub mod history;
pub mod profile;
pub mod search;