From a37a5ccaf4c067bce388aa5e434b93aa72611884 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 21 Oct 2023 20:53:47 +0200 Subject: [PATCH] group contacts under an umbrella of aliases /c and /contact --- src/main.rs | 3 +-- src/routes/contact.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5aafe56..cc2b2a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,8 +52,7 @@ async fn main() -> Result<()> { .service(cv::page) .service(gaming::page) .service(memorial::page) - .service(contact::page) - .service(contact::service_redirection) + .configure(contact::pages) .service(portfolio::page) .service(setup::page) .service(web3::page) diff --git a/src/routes/contact.rs b/src/routes/contact.rs index db2e114..ba9d44b 100644 --- a/src/routes/contact.rs +++ b/src/routes/contact.rs @@ -12,7 +12,19 @@ use crate::{ template::{Infos, NavBar}, }; -#[get("/contact")] +pub fn pages(cfg: &mut web::ServiceConfig) { + // Here define the services used + let routes = |route_path| { + web::scope(route_path) + .service(page) + .service(service_redirection) + }; + + // Here define the routes aliases + cfg.service(routes("/contact")).service(routes("/c")); +} + +#[get("")] async fn page(req: HttpRequest, config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_page( config.get_ref().to_owned(), @@ -21,11 +33,13 @@ async fn page(req: HttpRequest, config: web::Data) -> impl Responder { } #[routes] -#[get("/contact/{service}")] -#[get("/contact/{service}/{scope}")] +#[get("/{service}")] +#[get("/{service}/{scope}")] async fn service_redirection(req: HttpRequest) -> impl Responder { let info = req.match_info(); let find_redirection = match info.query("service") { + // TODO: XML file with link, so it's not hardcoded here + /* Socials links */ "twitter" => Some("https://twitter.com/Mylloon".to_owned()), "mastodon" => Some("https://piaille.fr/@mylloon".to_owned()),