extend 404 handler to handle all the requests our custom_ routes dont
This commit is contained in:
		
							parent
							
								
									6253adf768
								
							
						
					
					
						commit
						92fbd174eb
					
				| @ -1,6 +1,6 @@ | |||||||
| use plume_models::{Error, PlumeRocket}; | use plume_models::{instance::Instance, Error, PlumeRocket}; | ||||||
| use rocket::{ | use rocket::{ | ||||||
|     response::{self, Responder}, |     response::{self, Redirect, Responder}, | ||||||
|     Request, |     Request, | ||||||
| }; | }; | ||||||
| use template_utils::{IntoContext, Ructe}; | use template_utils::{IntoContext, Ructe}; | ||||||
| @ -29,9 +29,26 @@ impl<'r> Responder<'r> for ErrorPage { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[catch(404)] | #[catch(404)] | ||||||
| pub fn not_found(req: &Request) -> Ructe { | pub fn not_found(req: &Request) -> Result<Ructe, Redirect> { | ||||||
|     let rockets = req.guard::<PlumeRocket>().unwrap(); |     let rockets = req.guard::<PlumeRocket>().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::<Vec<&str>>() | ||||||
|  |             .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)] | #[catch(422)] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user