1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*!
Handlers for HTTP requests to `/api/v0/healthz`.
*/

use sqlx::Executor;

use crate::prelude::*;

/**
POST `/api/v0/healthz` Tells whether the server is healthy.
*/
pub async fn healthz(pool: web::Data<PgPool>) -> ControllerResult<web::Json<bool>> {
    let mut conn = pool.acquire().await?;
    let token = skip_authorize();
    let _res = conn.execute("SELECT 1").await?;
    token.authorized_ok(web::Json(true))
}

pub fn _add_routes(cfg: &mut ServiceConfig) {
    cfg.route("", web::get().to(healthz));
}