404: add page

This commit is contained in:
Agahnim 2026-03-19 18:10:05 +01:00
parent 6325e0568c
commit c4c49dee6b
6 changed files with 43 additions and 2 deletions

View file

@ -1,4 +1,4 @@
use agahnim_web_v2::templates::index::home;
use agahnim_web_v2::templates::{index::home, notfound::notfound};
use axum::{Router, routing::get};
use tower_http::services::ServeDir;
#[cfg(debug_assertions)]
@ -8,7 +8,8 @@ use tower_livereload::LiveReloadLayer;
async fn main() {
let app = Router::new()
.route("/", get(home))
.nest_service("/static", ServeDir::new("static"));
.nest_service("/static", ServeDir::new("static"))
.fallback(notfound);
// We need to include this flag so that the live reload layer isn't included when the server is built
#[cfg(debug_assertions)]

View file

@ -1 +1,2 @@
pub mod index;
pub mod notfound;

10
src/templates/notfound.rs Normal file
View file

@ -0,0 +1,10 @@
use askama::Template;
use axum::response::{Html, IntoResponse};
#[derive(Template)]
#[template(path = "notfound.html")]
struct NotfoundTemplate;
pub async fn notfound() -> impl IntoResponse {
Html(NotfoundTemplate.render().unwrap())
}