From 84979849eb3e08fabe5d7db3455f72d616b12959 Mon Sep 17 00:00:00 2001 From: Cappy Ishihara Date: Mon, 3 Jun 2024 01:05:36 +0700 Subject: [PATCH] Add health check endpoint --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 35df3a1..e5fccae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,6 +94,14 @@ pub struct AppState { advanced_users: Arc>, } +/// Assert health of the server +/// If times out, the server is considered dead, so we can return basically anything +async fn health_check() -> String { + // tokio::time::sleep(std::time::Duration::from_secs(5)).await; + "ok".to_string() +} + + #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::fmt() @@ -148,6 +156,7 @@ async fn main() -> Result<()> { .nest("/api", api) .route("/api/", get(api_auth::status)) .route("/ws", get(handler)) + .route("/health", get(health_check)) .route_layer(from_extractor::()) .with_state(state) .layer(TraceLayer::new_for_http().on_request(()));