diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 6d25118..f3bc6b4 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -26,3 +26,7 @@ pub async fn signalboost(state: Arc) -> Result { let state = state.clone(); Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone())) } + +pub async fn not_found(path: String) -> Result { + Response::builder().html(|o| templates::notfound_html(o, path)) +} diff --git a/src/main.rs b/src/main.rs index dd2e83b..57396ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,8 @@ async fn main() -> Result<()> { .into(), )?); + let healthcheck = warp::get().and(warp::path(".within").and(warp::path("health")).map(|| "OK")); + let routes = warp::get() .and(path::end().and_then(handlers::index)) .or(warp::path!("contact").and_then(handlers::contact)) @@ -40,9 +42,21 @@ async fn main() -> Result<()> { let files = warp::path("static") .and(warp::fs::dir("./static")) - .or(warp::path("css").and(warp::fs::dir("./css"))); + .or(warp::path("css").and(warp::fs::dir("./css"))) + .or(warp::path("sw.js").and(warp::fs::file("./static/js/sw.js"))) + .or(warp::path("robots.txt").and(warp::fs::file("./static/robots.txt"))); - let site = routes.or(files).with(warp::log(APPLICATION_NAME)); + let site = routes + .or(files) + .map(|reply| { + warp::reply::with_header( + reply, + "X-Hacker", + "If you are reading this, check out /signalboost to find people for your team", + ) + }) + .or(healthcheck) + .with(warp::log(APPLICATION_NAME)); warp::serve(site).run(([127, 0, 0, 1], 3030)).await; diff --git a/templates/error.rs.html b/templates/error.rs.html new file mode 100644 index 0000000..f97decc --- /dev/null +++ b/templates/error.rs.html @@ -0,0 +1,13 @@ +@use super::{header_html, footer_html}; + +@(why: String) + +@:header_html(Some("Error"), None) + +

Error

+ +
@why
+ +

You could try to go home or report this issue so it can be fixed.

+ +@:footer_html() diff --git a/templates/notfound.rs.html b/templates/notfound.rs.html new file mode 100644 index 0000000..cc5a735 --- /dev/null +++ b/templates/notfound.rs.html @@ -0,0 +1,11 @@ +@use super::{header_html, footer_html}; + +@(path: String) + +@:header_html(Some("Not Found"), None) + +

Not Found

+ +

The path at @path could not be found. If you expected this path to exist, please report this issue so it can be fixed.

+ +@:footer_html()