Browse Source
add not_found catcher for 404 errors
pull/2768/head
Stefan Melmuk
2 years ago
No known key found for this signature in database
GPG Key ID: 817020C608FE9C09
3 changed files with
16 additions and
1 deletions
-
src/api/mod.rs
-
src/api/web.rs
-
src/main.rs
|
|
@ -19,6 +19,7 @@ pub use crate::api::{ |
|
|
|
identity::routes as identity_routes, |
|
|
|
notifications::routes as notifications_routes, |
|
|
|
notifications::{start_notification_server, Notify, UpdateType}, |
|
|
|
web::catchers as web_catchers, |
|
|
|
web::routes as web_routes, |
|
|
|
}; |
|
|
|
use crate::util; |
|
|
|
|
|
@ -1,7 +1,7 @@ |
|
|
|
use std::path::{Path, PathBuf}; |
|
|
|
|
|
|
|
use rocket::serde::json::Json; |
|
|
|
use rocket::{fs::NamedFile, http::ContentType, Route}; |
|
|
|
use rocket::{fs::NamedFile, http::ContentType, Catcher, Route}; |
|
|
|
use serde_json::Value; |
|
|
|
|
|
|
|
use crate::{ |
|
|
@ -21,6 +21,19 @@ pub fn routes() -> Vec<Route> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pub fn catchers() -> Vec<Catcher> { |
|
|
|
if CONFIG.web_vault_enabled() { |
|
|
|
catchers![not_found] |
|
|
|
} else { |
|
|
|
catchers![] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[catch(404)] |
|
|
|
async fn not_found() -> Cached<Option<NamedFile>> { |
|
|
|
Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("404.html")).await.ok(), false) |
|
|
|
} |
|
|
|
|
|
|
|
#[get("/")] |
|
|
|
async fn web_index() -> Cached<Option<NamedFile>> { |
|
|
|
Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("index.html")).await.ok(), false) |
|
|
|
|
|
@ -425,6 +425,7 @@ async fn launch_rocket(pool: db::DbPool, extra_debug: bool) -> Result<(), Error> |
|
|
|
.mount([basepath, "/identity"].concat(), api::identity_routes()) |
|
|
|
.mount([basepath, "/icons"].concat(), api::icons_routes()) |
|
|
|
.mount([basepath, "/notifications"].concat(), api::notifications_routes()) |
|
|
|
.register([basepath, "/"].concat(), api::web_catchers()) |
|
|
|
.manage(pool) |
|
|
|
.manage(api::start_notification_server()) |
|
|
|
.attach(util::AppHeaders()) |
|
|
|