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 00000000..a76ddb04 Binary files /dev/null and b/src/static/images/404.png differ 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.

+
+ + + +