make a 404 page
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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!";
|
||||
|
||||
19
src/website/pages/notfound.rs
Normal file
19
src/website/pages/notfound.rs
Normal 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(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user