add 404 page
All checks were successful
build docker container automatically / build (push) Successful in 4m14s
All checks were successful
build docker container automatically / build (push) Successful in 4m14s
This commit is contained in:
@ -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,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
30
src/main.rs
30
src/main.rs
@ -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! {
|
||||
|
||||
@ -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
17
src/views/not_found.rs
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user