diff options
author | Joris | 2021-02-13 09:50:42 +0100 |
---|---|---|
committer | Joris | 2021-02-13 09:50:42 +0100 |
commit | 6f7c47a33caae84e2f99ad3bfe61a4bd0176bd1a (patch) | |
tree | 87cc7483e84d0b2d15bc9b4a433617d48cf1548b | |
parent | c00d85d2fc5a50febdc01364e5852bf4668fe201 (diff) |
Add status page
-rw-r--r-- | shell.nix | 1 | ||||
-rw-r--r-- | src/controller/utils.rs | 12 | ||||
-rw-r--r-- | src/routes.rs | 2 |
3 files changed, 14 insertions, 1 deletions
@@ -18,7 +18,6 @@ with import "${nixpkgs-mozilla.out}/rust-overlay.nix" pkgs pkgs; pkgs.mkShell { buildInputs = [ - # rustChannels.nightly.rust ((rustChannelOf { channel = "1.49.0"; }).rust) cargo-watch lld diff --git a/src/controller/utils.rs b/src/controller/utils.rs index 225f8a4..544cdf8 100644 --- a/src/controller/utils.rs +++ b/src/controller/utils.rs @@ -96,6 +96,18 @@ pub fn template( ) } +pub fn text(str: String) -> Response<Body> { + let mut response = Response::new(str.into()); + *response.status_mut() = StatusCode::OK; + response +} + +pub fn ok() -> Response<Body> { + let mut response = Response::default(); + *response.status_mut() = StatusCode::OK; + response +} + pub fn redirect(uri: &str) -> Response<Body> { let mut response = Response::default(); *response.status_mut() = StatusCode::MOVED_PERMANENTLY; diff --git a/src/routes.rs b/src/routes.rs index 3d76ab1..982e5ef 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -25,6 +25,8 @@ pub async fn routes( let path = &uri.path().split('/').collect::<Vec<&str>>()[1..]; let response = match (method, path) { + (&Method::HEAD, ["status"]) => controller::utils::ok(), + (&Method::GET, ["status"]) => controller::utils::text("ok".to_string()), (&Method::GET, ["login"]) => { controller::login::page(&assets, &templates, None).await } |