change index to templates using handlebars

using a handlebars instance in ApiConfig, to cache the templates
as long as possible, this is currently ok, as the index template
can only change when the whole package changes

if we split this in the future, we have to trigger a reload of
the daemon on gui package upgrade (so that the template gets reloaded)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak authored and Dietmar Maurer committed 2020-04-29 17:05:53 +02:00
1 parent bc0d03885c
commit f9e3b1104e
8 files changed
+87 -49

No files matched your search

+11 -4
View 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(