]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/server/config.rs
change index to templates using handlebars
[proxmox-backup.git] / src / server / config.rs
index d9aa076c40eef5d22685db853fa29c9b9f0cbbbc..e8b3c94653811baf1e1f01b87c65641e7c1741c3 100644 (file)
@@ -1,7 +1,9 @@
 use std::collections::HashMap;
 use std::path::{PathBuf};
+use anyhow::Error;
 
 use hyper::Method;
+use handlebars::Handlebars;
 
 use proxmox::api::{ApiMethod, Router, RpcEnvironmentType};
 
@@ -10,17 +12,22 @@ pub struct ApiConfig {
     router: &'static Router,
     aliases: HashMap<String, PathBuf>,
     env_type: RpcEnvironmentType,
+    pub templates: Handlebars<'static>,
 }
 
 impl ApiConfig {
 
-    pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static Router, env_type: RpcEnvironmentType) -> Self {
-        Self {
-            basedir: basedir.into(),
+    pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static Router, env_type: RpcEnvironmentType) -> Result<Self, Error> {
+        let mut templates = Handlebars::new();
+        let basedir = basedir.into();
+        templates.register_template_file("index", basedir.join("index.hbs"))?;
+        Ok(Self {
+            basedir,
             router,
             aliases: HashMap::new(),
             env_type,
-        }
+            templates
+        })
     }
 
     pub fn find_method(