Skip to content

Commit

Permalink
Add /healthz healthcheck endpoint (#20)
Browse files Browse the repository at this point in the history
It merely returns "OK" with a 200 status code
  • Loading branch information
kevinastone authored Oct 20, 2024
1 parent c9ee009 commit 611a483
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/service/healthz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::http::{ok, Request, Result};

pub async fn healthz(_req: Request) -> Result {
ok("OK")
}

#[cfg(test)]
mod test {
use super::*;
use crate::test::*;
use hyper::http::StatusCode;

#[tokio::test]
async fn test_healthz() {
let res = request().handle(healthz).await.unwrap();

assert_eq!(res.status(), StatusCode::OK);
let body = res.read_body_utf8().await.unwrap();
assert_eq!(body, "OK");
}
}
6 changes: 5 additions & 1 deletion src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod cache;
mod cookies;
mod delay;
mod headers;
mod healthz;
mod index;
mod ip;
mod method;
Expand Down Expand Up @@ -161,5 +162,8 @@ pub fn router() -> Router {
let routes = std::iter::once(&index_route).chain(builder.routes());
let index: crate::service::index::Index = routes.into();

builder.install(index, index_route).build()
builder
.install(crate::service::healthz::healthz, route(path!("healthz")))
.install(index, index_route)
.build()
}

0 comments on commit 611a483

Please sign in to comment.