add 404 page
All checks were successful
build docker container automatically / build (push) Successful in 4m14s

This commit is contained in:
2026-04-20 12:12:36 +02:00
parent d74ca76e44
commit 517ecbd359
4 changed files with 51 additions and 2 deletions

View File

@ -15,7 +15,7 @@ impl ServerConfig {
db_url: std::env::var("HTTPSERVER_DATABASE_URL").expect("missing HTTPSERVER_DATABASE_URL"),
upload_storage_limit_soft: 1024 * 1024 * 1024 * 200,
upload_storage_limit_hard: 1024 * 1024 * 1024 * 250,
upload_storage_limit_hard: 1024 * 1024 * 1024 * 300,
}
}

View File

@ -1,12 +1,19 @@
use dioxus::prelude::*;
use crate::dioxus_fullstack::FullstackContext;
use tracing::Level;
pub mod config;
use crate::components::toast::ToastProvider;
use crate::views::{Upload, UploadInfo, Home};
use crate::views::{
Upload,
UploadInfo,
Home,
NotFound
};
#[cfg(feature = "server")]
use crate::config::ServerConfig;
@ -17,12 +24,17 @@ mod views;
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
#[layout(ErrorLayout)]
#[route("/")]
Home { },
#[route("/upload/:file")]
UploadInfo { file: String },
#[route("/upload")]
Upload { },
#[route("/:..route")]
NotFound { route: Vec<String> },
}
@ -37,6 +49,22 @@ fn main() {
dioxus::launch(App);
}
#[component]
fn ErrorLayout() -> Element {
rsx! {
ErrorBoundary {
handle_error: move |err: ErrorContext| {
let http_error = FullstackContext::commit_error_status(err.error().unwrap());
match http_error.status {
StatusCode::NOT_FOUND => rsx! { div { "404 - Page not found" } },
_ => rsx! { div { "An unknown error occurred" } },
}
},
Outlet::<Route> {}
}
}
}
#[component]
fn App() -> Element {
rsx! {

View File

@ -3,3 +3,7 @@ pub use upload::{Upload, UploadInfo};
mod home;
pub use home::Home;
mod not_found;
pub use not_found::NotFound;

17
src/views/not_found.rs Normal file
View File

@ -0,0 +1,17 @@
use dioxus::prelude::*;
use crate::Route;
#[component]
pub fn NotFound(route: Vec<String>) -> Element {
let full_path = "/".to_owned() + &route.join("/");
rsx! {
h1 { "404 - Page not found" }
p { "Tried to access: {full_path}" }
Link {
to: Route::Home { },
class: "height-20px text-blue-700 underline py-1",
"Go back Home"
}
}
}