1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.

//! Route handlers for our heathcheck endpoints.
//!
//! * `GET /__version__`
//! * `GET /__lbheartbeat__`
//! * `GET /__heartbeat__`

use reqwest::Client as RequestClient;
use rocket::State;
use rocket_contrib::Json;
use serde_json;

use crate::{settings::Settings, types::error::AppResult};

#[cfg(test)]
mod test;

#[get("/__version__")]
fn version() -> Json {
    Json(serde_json::from_str(include_str!("../../../version.json")).unwrap())
}

#[get("/__lbheartbeat__")]
fn lbheartbeat() -> Json {
    Json(json!({}))
}

#[get("/__heartbeat__")]
fn heartbeat(settings: State<Settings>) -> AppResult<Json> {
    RequestClient::new()
        .get(&format!("{}__heartbeat__", settings.authdb.baseuri))
        .send()
        .map(|_| Ok(Json(json!({}))))?
}