From d209df9e10544b7c1fc8ebfdb3a7910400ba0289 Mon Sep 17 00:00:00 2001 From: Stefan Melmuk Date: Fri, 2 Dec 2022 17:58:27 +0100 Subject: [PATCH] use a custom 404 page to customize the 404 page you can copy the handlebar template `src/static/templates/404.hbs` to the TEMPLATES_FOLDER (defaults to `data/templates/`) --- resources/404.svg | 93 +++++++++++++++++++++++++++++++++++ src/api/web.rs | 15 ++++-- src/config.rs | 2 + src/static/images/404.png | Bin 0 -> 5042 bytes src/static/templates/404.hbs | 62 +++++++++++++++++++++++ 5 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 resources/404.svg create mode 100644 src/static/images/404.png create mode 100644 src/static/templates/404.hbs diff --git a/resources/404.svg b/resources/404.svg new file mode 100644 index 00000000..112db68d --- /dev/null +++ b/resources/404.svg @@ -0,0 +1,93 @@ + + + +404Return to the web vault? diff --git a/src/api/web.rs b/src/api/web.rs index e5485123..a7640cd9 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -1,11 +1,10 @@ use std::path::{Path, PathBuf}; -use rocket::serde::json::Json; -use rocket::{fs::NamedFile, http::ContentType, Catcher, Route}; +use rocket::{fs::NamedFile, http::ContentType, response::content::RawHtml as Html, serde::json::Json, Catcher, Route}; use serde_json::Value; use crate::{ - api::core::now, + api::{core::now, ApiResult}, error::Error, util::{Cached, SafeString}, CONFIG, @@ -30,8 +29,13 @@ pub fn catchers() -> Vec { } #[catch(404)] -async fn not_found() -> Cached> { - Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("404.html")).await.ok(), false) +fn not_found() -> ApiResult> { + // Return the page + let json = json!({ + "urlpath": CONFIG.domain_path() + }); + let text = CONFIG.render_template("404", &json)?; + Ok(Html(text)) } #[get("/")] @@ -91,6 +95,7 @@ fn alive(_conn: DbConn) -> Json { #[get("/vw_static/")] pub fn static_files(filename: String) -> Result<(ContentType, &'static [u8]), Error> { match filename.as_ref() { + "404.png" => Ok((ContentType::PNG, include_bytes!("../static/images/404.png"))), "mail-github.png" => Ok((ContentType::PNG, include_bytes!("../static/images/mail-github.png"))), "logo-gray.png" => Ok((ContentType::PNG, include_bytes!("../static/images/logo-gray.png"))), "error-x.svg" => Ok((ContentType::SVG, include_bytes!("../static/images/error-x.svg"))), diff --git a/src/config.rs b/src/config.rs index fbf0e412..eb776bb9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1123,6 +1123,8 @@ where reg!("admin/organizations"); reg!("admin/diagnostics"); + reg!("404"); + // And then load user templates to overwrite the defaults // Use .hbs extension for the files // Templates get registered with their relative name diff --git a/src/static/images/404.png b/src/static/images/404.png new file mode 100644 index 0000000000000000000000000000000000000000..a76ddb041d98ce06a441c5d606d5057b3b7c86e0 GIT binary patch literal 5042 zcma)ec{mha)c^Dq4Qi0Bn8?nMwV1JHM)oZd6~hq9GGxohpqeq(vSx{<$(Egj!bB6Y z&xEqaSSR~1mS}nP{Qmwu?|c5Z&w1`W=RBW#KIh)&6K`v6a*9iY3jhF|GBY)@0|1V( zj{NVy<3}rssJ#FH@MFx346lWcuYP=Zvuq?UuDwyQND46LN@@n?K>${dMbjI}w` zk{@6)iKBhWAp0fh6QcuM`m>x>?y6UYmH#Gdt18Buu}&wdCDY0#JD0$+Xl);*MKxnv zY5$7zLUR|)KUO@pYCnt9PkRrRUf*LZuyxuCQ2DZ8A$3~u_B>$?5Fg~d^h&ZH0f4Oeg`uHL9_vfM0T8iBgoV{%H8tu zfE@)+kA|%43o!*8gFt$3zkF2f4CYp;E&5?YhBvHBg)uz6sJta22To6TS3aU%c%2ck zoG%!vIzIe9Z#Azs{s^pQ=J<5j=#(MiX)ai$1)=qKKJq$WZ!HmZyI^qB8`|?_3y1zT z78nzmS89l8b@A@utXjG6RlN+`&+zNJJGzBcf><%U+`CsW13YIUN|5W|?Z zvjZ>MUSs9@OG?=r96HSN(?CSr`pecYMDE?+2d7{|=8}V7JD$W=e*e!8V#4r3z-Tpf z`drQeN-PklTbJlL1F6Ueb}?zvzcV@;A?fA_gKHf&p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?d00001 diff --git a/src/static/templates/404.hbs b/src/static/templates/404.hbs new file mode 100644 index 00000000..dc30b9e4 --- /dev/null +++ b/src/static/templates/404.hbs @@ -0,0 +1,62 @@ + + + + + + + + Page not found! + + + + + + + + +
+

Page not found!

+

Sorry, but the page you were looking for could not be found.

+

+ Return to the web vault?

+

You can return to the web-vault, or contact us.

+
+ + + +