chore: add home_path to WebServer config and fix APP_HOME
This commit is contained in:
parent
b7733d50e4
commit
952a3fd661
5 changed files with 60 additions and 48 deletions
|
|
@ -1,12 +1,9 @@
|
|||
//
|
||||
// Copyright 2021, Jesús Pérez Lorenzo
|
||||
//
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
module::Module,
|
||||
AppRunMode,
|
||||
appenv::AppEnv,
|
||||
};
|
||||
|
||||
use AppRunMode::{Pro,Premium};
|
||||
|
|
@ -22,21 +19,32 @@ pub struct AppInfo {
|
|||
pub appmode: AppRunMode,
|
||||
}
|
||||
impl AppInfo {
|
||||
pub async fn new(app_name: &str, webname: String, version: String, author: String) -> Self {
|
||||
let usedata = match std::fs::read_to_string(format!("{}.use",&envmnt::get_or("APP_HOME", ""))) {
|
||||
Ok(res) => res,
|
||||
// Err(e) => { println!("Error usedata: {}",e); String::from("")},
|
||||
Err(_) => String::from(""),
|
||||
};
|
||||
pub fn new(app_name: &str, webname: String, version: String, author: String) -> Self {
|
||||
Self {
|
||||
name: format!("{} Server",&app_name),
|
||||
webname,
|
||||
version,
|
||||
author,
|
||||
about: format!("{}: Boot app",&app_name),
|
||||
usedata,
|
||||
usedata: String::from(""),
|
||||
appmode: AppRunMode::default(),
|
||||
}
|
||||
}
|
||||
pub fn load_data(&self,app_env: &AppEnv) -> Self {
|
||||
let usedata = match std::fs::read_to_string(format!("{}/{}/.use",&envmnt::get_or("APP_HOME", ""),app_env.get_curr_websrvr_config().home_path)) {
|
||||
Ok(res) => res,
|
||||
// Err(e) => { println!("Error usedata: {}",e); String::from("")},
|
||||
Err(_) => String::from(""),
|
||||
};
|
||||
Self {
|
||||
name: self.name.to_owned(),
|
||||
webname: self.webname.to_owned(),
|
||||
version: self.version.to_owned(),
|
||||
author: self.author.to_owned(),
|
||||
about: self.about.to_owned(),
|
||||
usedata,
|
||||
appmode: self.appmode.to_owned(),
|
||||
}
|
||||
}
|
||||
#[must_use]
|
||||
pub fn can_do(&self, target: &str) -> bool {
|
||||
|
|
@ -58,14 +66,14 @@ impl AppInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppEnv {
|
||||
pub info: AppInfo,
|
||||
pub config: Config,
|
||||
pub debug_level: String,
|
||||
pub appkey: String,
|
||||
pub checked: bool,
|
||||
pub collections: HashMap<String, toml::Value>,
|
||||
pub modules: HashMap<String, Module>,
|
||||
// pub modules: HashMap<String, toml::Value>,
|
||||
}
|
||||
// #[derive(Clone, Debug)]
|
||||
// pub struct AppEnv {
|
||||
// pub info: AppInfo,
|
||||
// pub config: Config,
|
||||
// pub debug_level: String,
|
||||
// pub appkey: String,
|
||||
// pub checked: bool,
|
||||
// pub collections: HashMap<String, toml::Value>,
|
||||
// pub modules: HashMap<String, Module>,
|
||||
// // pub modules: HashMap<String, toml::Value>,
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ impl StoreLocal {
|
|||
#[derive(Clone, Debug, Deserialize, Default)]
|
||||
pub struct WebServer {
|
||||
pub name: String,
|
||||
pub home_path: String,
|
||||
pub resources_path: String,
|
||||
|
||||
pub certs_store_path: String,
|
||||
|
|
@ -171,31 +172,32 @@ impl Config {
|
|||
println!("Config Loaded successfully");
|
||||
}
|
||||
let app_home=envmnt::get_or("APP_HOME", "");
|
||||
if app_home.is_empty() {
|
||||
cfg
|
||||
} else {
|
||||
let mut app_cfg = cfg;
|
||||
// if app_home.is_empty() {
|
||||
// cfg
|
||||
// } else {
|
||||
let mut app_cfg: Config = cfg;
|
||||
let mut websrvrs: Vec<WebServer> = Vec::new();
|
||||
app_cfg.websrvrs.iter().enumerate().for_each(|(pos,it)| {
|
||||
let app_home_path=format!("{}/{}/",&app_home,&it.home_path);
|
||||
websrvrs.push(it.to_owned());
|
||||
websrvrs[pos].certs_store_path=format!("{}{}",&app_home,&it.certs_store_path);
|
||||
websrvrs[pos].resources_path=format!("{}{}",&app_home,&it.resources_path);
|
||||
websrvrs[pos].templates_path=format!("{}{}",&app_home,&it.templates_path);
|
||||
websrvrs[pos].defaults_path=format!("{}{}",&app_home,&it.defaults_path);
|
||||
websrvrs[pos].html_path=format!("{}{}",&app_home,&it.html_path);
|
||||
websrvrs[pos].dist_path=format!("{}{}",&app_home,&it.dist_path);
|
||||
websrvrs[pos].upload_path=format!("{}{}",&app_home,&it.upload_path);
|
||||
websrvrs[pos].auth_model_path=format!("{}{}",&app_home,&it.auth_model_path);
|
||||
websrvrs[pos].auth_policy_path=format!("{}{}",&app_home,&it.auth_policy_path);
|
||||
websrvrs[pos].usrs_store_target=format!("{}{}",&app_home,&it.usrs_store_target);
|
||||
websrvrs[pos].usrs_shadow_target=format!("{}{}",&app_home,&it.usrs_shadow_target);
|
||||
websrvrs[pos].certs_store_path=format!("{}{}",&app_home_path,&it.certs_store_path);
|
||||
websrvrs[pos].resources_path=format!("{}{}",&app_home_path,&it.resources_path);
|
||||
websrvrs[pos].templates_path=format!("{}{}",&app_home_path,&it.templates_path);
|
||||
websrvrs[pos].defaults_path=format!("{}{}",&app_home_path,&it.defaults_path);
|
||||
websrvrs[pos].html_path=format!("{}{}",&app_home_path,&it.html_path);
|
||||
websrvrs[pos].dist_path=format!("{}{}",&app_home_path,&it.dist_path);
|
||||
websrvrs[pos].upload_path=format!("{}{}",&app_home_path,&it.upload_path);
|
||||
websrvrs[pos].auth_model_path=format!("{}{}",&app_home_path,&it.auth_model_path);
|
||||
websrvrs[pos].auth_policy_path=format!("{}{}",&app_home_path,&it.auth_policy_path);
|
||||
websrvrs[pos].usrs_store_target=format!("{}{}",&app_home_path,&it.usrs_store_target);
|
||||
websrvrs[pos].usrs_shadow_target=format!("{}{}",&app_home_path,&it.usrs_shadow_target);
|
||||
});
|
||||
app_cfg.websrvrs = websrvrs;
|
||||
app_cfg.cache_path=format!("{}{}",&app_home,&app_cfg.cache_path);
|
||||
app_cfg.cache_lock_path=format!("{}{}",&app_home,&app_cfg.cache_lock_path);
|
||||
app_cfg.check_path=format!("{}{}",&app_home,&app_cfg.check_path);
|
||||
app_cfg
|
||||
}
|
||||
// }
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Config error: {}",e);
|
||||
|
|
|
|||
|
|
@ -53,14 +53,7 @@ impl Module {
|
|||
match toml::from_str(&content) {
|
||||
Ok(cfg) => {
|
||||
println!("Module Loaded successfully");
|
||||
let app_home=envmnt::get_or("APP_HOME", "");
|
||||
if app_home.is_empty() {
|
||||
cfg
|
||||
} else {
|
||||
let mut module_cfg = cfg;
|
||||
module_cfg.store_root=format!("{}{}",&app_home,&module_cfg.store_root);
|
||||
module_cfg
|
||||
}
|
||||
cfg
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Module error: {}",e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue