mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
feat: provide healthcheck API (#474)
This commit is contained in:
@@ -62,6 +62,7 @@ const INDEX_NAME: &str = "index.html";
|
||||
const BUF_SIZE: usize = 65536;
|
||||
const EDITABLE_TEXT_MAX_SIZE: u64 = 4194304; // 4M
|
||||
const RESUMABLE_UPLOAD_MIN_SIZE: u64 = 20971520; // 20M
|
||||
const HEALTH_CHECK_PATH: &str = "__dufs__/health";
|
||||
|
||||
pub struct Server {
|
||||
args: Args,
|
||||
@@ -171,7 +172,7 @@ impl Server {
|
||||
|
||||
if method == Method::GET
|
||||
&& self
|
||||
.handle_assets(&relative_path, headers, &mut res)
|
||||
.handle_internal(&relative_path, headers, &mut res)
|
||||
.await?
|
||||
{
|
||||
return Ok(res);
|
||||
@@ -738,7 +739,7 @@ impl Server {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_assets(
|
||||
async fn handle_internal(
|
||||
&self,
|
||||
req_path: &str,
|
||||
headers: &HeaderMap<HeaderValue>,
|
||||
@@ -789,6 +790,12 @@ impl Server {
|
||||
HeaderValue::from_static("nosniff"),
|
||||
);
|
||||
Ok(true)
|
||||
} else if req_path == HEALTH_CHECK_PATH {
|
||||
res.headers_mut()
|
||||
.typed_insert(ContentType::from(mime_guess::mime::APPLICATION_JSON));
|
||||
|
||||
*res.body_mut() = body_full(r#"{"status":"OK"}"#);
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user