Create health check endpoint
This commit is contained in:
23
src/api/health.rs
Normal file
23
src/api/health.rs
Normal 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())
|
||||
}
|
@ -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;
|
||||
|
Reference in New Issue
Block a user