Skip to content

Commit

Permalink
Add healthcheck endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cubetastic33 committed Feb 12, 2024
1 parent 3218533 commit 12a3f70
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn get_offline(cookies: Cookies) -> Template {
fn get_admin(client: State<Mutex<Client>>, mut cookies: Cookies) -> Template {
let mut page = String::from("admin_signin");
if let Some(hash) = cookies.get_private("admin_hash") {
if hash.value() == env::var("ADMIN_HASH").unwrap() {
if hash.value() == env::var("ADMIN_HASH").expect("Env var ADMIN_HASH not found") {
page = String::from("admin");
}
}
Expand All @@ -185,6 +185,13 @@ fn get_admin(client: State<Mutex<Client>>, mut cookies: Cookies) -> Template {
)
}

#[get("/health")]
fn get_health() -> Result<String, Box<dyn std::error::Error>> {
// Make GET request to healthcheck endpoint
reqwest::blocking::get(env::var("HEALTH_URL").expect("Env var HEALTH_URL not found"))?;
Ok(String::from("元気"))
}

#[post("/sentences", data = "<quiz_settings>")]
fn post_sentences(client: State<Mutex<Client>>, quiz_settings: Form<QuizSettings>) -> String {
get_sentences(&mut client.lock().unwrap(), quiz_settings)
Expand Down Expand Up @@ -393,6 +400,7 @@ fn rocket() -> rocket::Rocket {
get_custom_text,
get_offline,
get_admin,
get_health,
post_sentences,
post_report,
post_import_anki,
Expand Down

0 comments on commit 12a3f70

Please sign in to comment.