Created
August 24, 2020 22:48
-
-
Save BiosElement/d6f476c86e8b34e84e2ed8e9a1605674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::sync::Arc; | |
| use handlebars::Handlebars; | |
| use serde_json::json; | |
| pub async fn test(hb: Arc<Handlebars>) -> impl warp::Reply { | |
| hb.render("template_test", &json!({"username": "Warp"})).unwrap() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async fn main() { | |
| let mut hb = Handlebars::new(); | |
| hb.register_templates_directory(".hbs", "./templates") | |
| .unwrap(); | |
| let hb = Arc::new(hb); | |
| let hb = warp::any().map(move || hb.clone()); | |
| let templatetest = warp::get() | |
| .and(warp::path("templatetest")) | |
| .and(hb) | |
| .map(handlers::index_handler::test); | |
| warp::serve(templatetest)) | |
| .run(([127, 0, 0, 1], 3030)) | |
| .await; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment