From 92fbd174eb344951d2ddc5e752e47e80e3f63594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 28 May 2019 23:02:13 +0200 Subject: [PATCH] extend 404 handler to handle all the requests our custom_ routes dont --- src/routes/errors.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/routes/errors.rs b/src/routes/errors.rs index 1320a068..626be8f5 100644 --- a/src/routes/errors.rs +++ b/src/routes/errors.rs @@ -1,6 +1,6 @@ -use plume_models::{Error, PlumeRocket}; +use plume_models::{instance::Instance, Error, PlumeRocket}; use rocket::{ - response::{self, Responder}, + response::{self, Redirect, Responder}, Request, }; use template_utils::{IntoContext, Ructe}; @@ -29,9 +29,26 @@ impl<'r> Responder<'r> for ErrorPage { } #[catch(404)] -pub fn not_found(req: &Request) -> Ructe { +pub fn not_found(req: &Request) -> Result { let rockets = req.guard::().unwrap(); - render!(errors::not_found(&rockets.to_context())) + if req + .uri() + .segments() + .next() + .map(|path| path == "custom_domains") + .unwrap_or(false) + { + let path = req + .uri() + .segments() + .skip(2) + .collect::>() + .join("/"); + let public_domain = Instance::get_local().unwrap().public_domain; + Err(Redirect::to(format!("https://{}/{}", public_domain, path))) + } else { + Ok(render!(errors::not_found(&rockets.to_context()))) + } } #[catch(422)]