From bb27ad024d9b701b53960fc99c432518b2839b7a Mon Sep 17 00:00:00 2001 From: Alphonse Paix Date: Fri, 19 Sep 2025 19:34:06 +0200 Subject: [PATCH] 404 page --- src/routes.rs | 15 +++++++++++++++ src/startup.rs | 1 + templates/404.html | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 templates/404.html diff --git a/src/routes.rs b/src/routes.rs index 720e423..fe054f4 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -7,9 +7,24 @@ mod subscriptions; mod subscriptions_confirm; pub use admin::*; +use askama::Template; +use axum::response::{Html, IntoResponse, Response}; pub use health_check::*; pub use home::*; pub use login::*; pub use posts::*; +use reqwest::StatusCode; pub use subscriptions::*; pub use subscriptions_confirm::*; + +#[derive(Template)] +#[template(path = "../templates/404.html")] +struct NotFoundTemplate; + +pub async fn not_found() -> Response { + ( + StatusCode::NOT_FOUND, + Html(NotFoundTemplate.render().unwrap()), + ) + .into_response() +} diff --git a/src/startup.rs b/src/startup.rs index a82a5e7..0d7c3cf 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -150,5 +150,6 @@ pub fn app( }), ) .layer(SessionManagerLayer::new(redis_store).with_secure(false)) + .fallback(not_found) .with_state(app_state) } diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..4fd4c79 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} +{% block title %}Not Found{% endblock %} +{% block content %} +
+
+

404

+

Not Found

+

+ Sorry, we couldn't find the page you're looking for. The page may have been moved, deleted, or the URL might be incorrect. +

+ +
+
+{% endblock %}