diff options
author | Yigit Sever | 2021-04-15 00:32:28 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-15 03:46:30 +0300 |
commit | be037a6b35056ec8aa8f75e56becd009bc7c01f2 (patch) | |
tree | 65bdca7c1327fb200e2060374b39579b677e2903 /src | |
parent | 7bcdcbcaa5bc8b03f8838630761bb99bb2cecef0 (diff) | |
download | gradecoin-be037a6b35056ec8aa8f75e56becd009bc7c01f2.tar.gz gradecoin-be037a6b35056ec8aa8f75e56becd009bc7c01f2.tar.bz2 gradecoin-be037a6b35056ec8aa8f75e56becd009bc7c01f2.zip |
Add template support
We are now serving static HTML alongside Gradecoin REST
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 19 | ||||
-rw-r--r-- | src/routes.rs | 6 |
2 files changed, 22 insertions, 3 deletions
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 @@ | |||
1 | /// API handlers, the ends of each filter chain | ||
2 | use aes::Aes128; | 1 | use aes::Aes128; |
2 | /// API handlers, the ends of each filter chain | ||
3 | use askama::Template; | ||
3 | use base64; | 4 | use base64; |
4 | use blake2::{Blake2s, Digest}; | 5 | use blake2::{Blake2s, Digest}; |
5 | use block_modes::block_padding::Pkcs7; | 6 | use block_modes::block_padding::Pkcs7; |
@@ -599,3 +600,19 @@ fn authorize_proposer(jwt_token: String, user_pem: &String) -> Result<TokenData< | |||
599 | 600 | ||
600 | Ok(token_payload) | 601 | Ok(token_payload) |
601 | } | 602 | } |
603 | |||
604 | #[derive(Template)] | ||
605 | #[template(path = "welcome.html")] | ||
606 | struct WelcomeTemplate<'a> { | ||
607 | title: &'a str, | ||
608 | body: &'a str, | ||
609 | } | ||
610 | |||
611 | pub async fn welcome_handler() -> Result<impl warp::Reply, warp::Rejection> { | ||
612 | let template = WelcomeTemplate { | ||
613 | title: "Welcome", | ||
614 | body: "To The Bookstore!", | ||
615 | }; | ||
616 | let res = template.render().unwrap(); | ||
617 | Ok(warp::reply::html(res)) | ||
618 | } | ||
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; | |||
7 | 7 | ||
8 | /// Every route combined | 8 | /// Every route combined |
9 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 9 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
10 | transaction_list(db.clone()) | 10 | let welcome_route = warp::path::end().and_then(handlers::welcome_handler); |
11 | |||
12 | welcome_route | ||
13 | .or(transaction_list(db.clone())) | ||
11 | .or(register_user(db.clone())) | 14 | .or(register_user(db.clone())) |
12 | .or(auth_transaction_propose(db.clone())) | 15 | .or(auth_transaction_propose(db.clone())) |
13 | .or(auth_block_propose(db.clone())) | 16 | .or(auth_block_propose(db.clone())) |
@@ -60,4 +63,3 @@ pub fn auth_block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = R | |||
60 | .and(custom_filters::with_db(db)) | 63 | .and(custom_filters::with_db(db)) |
61 | .and_then(handlers::authorized_propose_block) | 64 | .and_then(handlers::authorized_propose_block) |
62 | } | 65 | } |
63 | |||