headless_lms_server/controllers/
health.rs

1/*!
2Handlers for HTTP requests to `/api/v0/health`.
3*/
4
5use sqlx::Executor;
6
7use crate::controllers::main_frontend::status::system_health;
8use crate::prelude::*;
9
10/**
11GET `/api/v0/healthz/connectivity` Tells whether the server is healthy (database connectivity).
12*/
13pub async fn connectivity(pool: web::Data<PgPool>) -> ControllerResult<web::Json<bool>> {
14    let mut conn = pool.acquire().await?;
15    let token = skip_authorize();
16    let _res = conn.execute("SELECT 1").await?;
17    token.authorized_ok(web::Json(true))
18}
19
20/**
21GET `/api/v0/healthz/up` Returns true to indicate the service is up.
22*/
23pub async fn up() -> ControllerResult<web::Json<bool>> {
24    let token = skip_authorize();
25    token.authorized_ok(web::Json(true))
26}
27
28pub fn _add_routes(cfg: &mut ServiceConfig) {
29    cfg.route("/connectivity", web::get().to(connectivity))
30        .route("/system", web::get().to(system_health))
31        .route("/up", web::get().to(up));
32}