From 7f91412ddf3895214a8b56ac520ea7a60c0d24a1 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 15 Apr 2021 00:32:28 +0300 Subject: [WIP] Add template support --- src/handlers.rs | 19 ++++++++++++++++++- src/routes.rs | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/handlers.rs b/src/handlers.rs index a8c9947..b3a6fa8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,5 +1,6 @@ -/// API handlers, the ends of each filter chain use aes::Aes128; +/// API handlers, the ends of each filter chain +use askama::Template; use base64; use blake2::{Blake2s, Digest}; use block_modes::block_padding::Pkcs7; @@ -599,3 +600,19 @@ fn authorize_proposer(jwt_token: String, user_pem: &String) -> Result { + title: &'a str, + body: &'a str, +} + +pub async fn welcome_handler() -> Result { + let template = WelcomeTemplate { + title: "Welcome", + body: "To The Bookstore!", + }; + let res = template.render().unwrap(); + Ok(warp::reply::html(res)) +} diff --git a/src/routes.rs b/src/routes.rs index 280de35..f8d9605 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -7,7 +7,10 @@ use crate::schema::Db; /// Every route combined pub fn consensus_routes(db: Db) -> impl Filter + Clone { - transaction_list(db.clone()) + let welcome_route = warp::path::end().and_then(handlers::welcome_handler); + + welcome_route + .or(transaction_list(db.clone())) .or(register_user(db.clone())) .or(auth_transaction_propose(db.clone())) .or(auth_block_propose(db.clone())) @@ -60,4 +63,3 @@ pub fn auth_block_propose(db: Db) -> impl Filter impl Filter + Clone { - let welcome_route = warp::path::end().and_then(handlers::welcome_handler); + // Remember when we wanted to implement templating + // Why would we? Just put a staic webpage under /public (next to Cargo.toml) and place it and + // the end of the filter chain - welcome_route - .or(transaction_list(db.clone())) + // Fully fledged website support, phew! + let static_route = warp::any().and(warp::fs::dir("public")); + + transaction_list(db.clone()) .or(register_user(db.clone())) .or(auth_transaction_propose(db.clone())) .or(auth_block_propose(db.clone())) .or(block_list(db.clone())) + .or(static_route) } /// POST /register warp route -- cgit v1.2.3-70-g09d2 From ca9146db3670cac5a82a3b89b998eee12ff27b44 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 15 Apr 2021 03:40:20 +0300 Subject: shed unused function --- src/handlers.rs | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src') diff --git a/src/handlers.rs b/src/handlers.rs index b3a6fa8..7135190 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -194,17 +194,6 @@ pub async fn authenticate_user( Ok(warp::reply::with_status(res_json, StatusCode::CREATED)) } -// fn shed_pem_header_footer(maybe_key: String) -> Result, String> { -// let der_encoded = maybe_key -// .lines() -// .filter(|line| !line.starts_with("-")) -// .fold(String::new(), |mut data, line| { -// data.push_str(&line); -// data -// }); -// Ok(base64::decode(&der_encoded).expect("failed to decode base64 content")) -// } - /// GET /transaction /// Returns JSON array of transactions /// Cannot fail -- cgit v1.2.3-70-g09d2