make a 404 page

This commit is contained in:
2025-09-24 16:26:30 +02:00
parent c54a1a1762
commit a36f2c86a7
6 changed files with 60 additions and 4 deletions

View File

@@ -2,11 +2,11 @@ use std::convert::Infallible;
use axum::{
body::Body,
http::{Request, StatusCode, header},
http::{Request, header},
response::{IntoResponse, Response},
};
use crate::website::pages::index::page_index;
use crate::website::pages::{index::page_index, notfound::page_notfound};
mod pages;
@@ -22,6 +22,6 @@ pub async fn website_service(req: Request<Body>) -> Result<Response, Infallible>
"styles.css" => ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS).into_response(),
"favicon.svg" => ([(header::CONTENT_TYPE, "image/svg+xml")], FAVICON_SVG).into_response(),
"favicon-x64.png" => ([(header::CONTENT_TYPE, "image/png")], FAVICON_X64).into_response(),
_ => StatusCode::NOT_FOUND.into_response(),
_ => page_notfound().await,
})
}

View File

@@ -1,4 +1,5 @@
pub mod index;
pub mod notfound;
const INTERNAL_SERVER_ERROR_MSG: &str =
"An internal server error occured while rendering your HTML. Sorry!";

View File

@@ -0,0 +1,19 @@
use askama::Template;
use axum::{
http::StatusCode,
response::{Html, IntoResponse, Response},
};
use crate::website::pages::INTERNAL_SERVER_ERROR_MSG;
#[derive(Template)]
#[template(path = "notfound.html")]
struct PageNotFound;
pub async fn page_notfound() -> Response {
let a = PageNotFound;
match a.render() {
Ok(res) => (StatusCode::OK, Html(res)).into_response(),
Err(_e) => (StatusCode::INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MSG).into_response(),
}
}