Skip to content

Instantly share code, notes, and snippets.

@BiosElement
Created August 24, 2020 22:48
Show Gist options
  • Select an option

  • Save BiosElement/d6f476c86e8b34e84e2ed8e9a1605674 to your computer and use it in GitHub Desktop.

Select an option

Save BiosElement/d6f476c86e8b34e84e2ed8e9a1605674 to your computer and use it in GitHub Desktop.
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()
}
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