diff --git a/app_auth_handlers/src/lib.rs b/app_auth_handlers/src/lib.rs index 937bc4a..c810c58 100644 --- a/app_auth_handlers/src/lib.rs +++ b/app_auth_handlers/src/lib.rs @@ -31,7 +31,7 @@ pub async fn login_handler ( let mut ctx = reqenv.ctx(); let req_module = ""; let app_module: &str; - if ! req_module.is_empty() && req_module != reqenv.config().default_module.as_str() { + if ! req_module.is_empty() && req_module != reqenv.websrvr().default_module.as_str() { app_module = req_module; } else { app_module = ""; @@ -45,7 +45,7 @@ pub async fn login_handler ( match reqenv .render_page( &mut ctx, - reqenv.config().templates_path.as_str(), + reqenv.websrvr().templates_path.as_str(), "login/index.html", "index.html", format!("login/{}.toml", lang.to_owned()) @@ -95,9 +95,9 @@ pub async fn loginin_handler( Ok(token) => // Ok(token.to_string()),o match reqenv.check_authentication(token.to_owned()).await { Ok(usrctx) => { - let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.config().resources_path,&body.mapkey,&usrctx.user_id); + let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&body.mapkey,&usrctx.user_id); if ! std::path::Path::new(&path).exists() { - path = format!("{}/profiles/{}/defs.yaml",reqenv.config().resources_path,&prfx); + path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx); } let content = Profile::load_fs_content(path.into()); // let lang = opts.lang.unwrap_or_else(|| String::from("es")); @@ -144,9 +144,9 @@ pub async fn checkin_handler( // let allow_origin = reqenv.config().allow_origin; match &reqenv.check_authentication(body.data.to_owned()).await { Ok(usrctx) => { // Ok(token.to_string()), - let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.config().resources_path,&body.mapkey,&usrctx.user_id); + let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&body.mapkey,&usrctx.user_id); if ! std::path::Path::new(&path).exists() { - path = format!("{}/profiles/{}/defs.yaml",reqenv.config().resources_path,&body.mapkey); + path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&body.mapkey); } let content = Profile::load_fs_content(path.into()); let res = Profile::to_yaml(content); diff --git a/app_file_handlers/src/lib.rs b/app_file_handlers/src/lib.rs index e04b0b7..e42cd3a 100644 --- a/app_file_handlers/src/lib.rs +++ b/app_file_handlers/src/lib.rs @@ -60,7 +60,7 @@ pub async fn upload_handler ( let mut ctx = req.ctx(); let req_module = ""; let app_module: &str; - if ! req_module.is_empty() && req_module != req.config().default_module.as_str() { + if ! req_module.is_empty() && req_module != req.websrvr().default_module.as_str() { app_module = req_module; } else { app_module = ""; @@ -73,7 +73,7 @@ pub async fn upload_handler ( match req .render_page( &mut ctx, - req.config().templates_path.as_str(), + req.websrvr().templates_path.as_str(), "upload/index.html", "index.html", format!("upload/{}.toml", lang.to_owned()) @@ -135,7 +135,7 @@ pub async fn uploadin_handler( // let allow_origin = req.config().allow_origin; match req.user_authentication().await { Ok(auth) => { - let mut files_path = format!("{}/{}", req.config().upload_path,&auth.user_id); + let mut files_path = format!("{}/{}", req.websrvr().upload_path,&auth.user_id); if ! std::path::Path::new(&files_path).exists() { std::fs::create_dir(&files_path).unwrap_or_else(|e| { println!("Error create dir {}: {}", &files_path,e); files_path = String::from("");}); if files_path.is_empty() { diff --git a/reqenv/src/lib.rs b/reqenv/src/lib.rs index 1601763..f4686f9 100644 --- a/reqenv/src/lib.rs +++ b/reqenv/src/lib.rs @@ -16,7 +16,7 @@ use warp::{ use reqtasks::ReqTasks; use app_env::{ appenv::AppEnv, - config::Config, + config::{Config, WebServer}, module::Module, AppStore, // AppData, @@ -95,6 +95,10 @@ impl ReqEnv { #[must_use] pub fn config(&self) -> Config { self.req.config() + } + #[must_use] + pub fn websrvr(&self) -> WebServer { + self.req.config().websrvrs[self.req.env().curr_web].to_owned() } #[must_use] pub fn module(&self) -> Module { diff --git a/reqtasks/src/lib.rs b/reqtasks/src/lib.rs index 1759450..7114eed 100644 --- a/reqtasks/src/lib.rs +++ b/reqtasks/src/lib.rs @@ -14,7 +14,7 @@ use tera::Tera; use app_env::{ AppStore, appenv::AppEnv, - config::Config, + config::{Config,WebServer}, module::Module, appdata::AppData }; @@ -118,6 +118,11 @@ impl ReqTasks { pub fn config(&self) -> Config { self.app_data.env.config.to_owned() } + /// Get `AppEnv` Config + #[must_use] + pub fn websrvr(&self) -> WebServer { + self.app_data.env.config.websrvrs[self.app_data.env.curr_web].to_owned() + } #[must_use] pub fn module(&self) -> Module { self.app_data.env.get_module(&self.key_module) @@ -136,13 +141,13 @@ impl ReqTasks { // } /// Get Lang list from header - accept-language /// get first one but only root part as first two characters (es in case of es-ES) - /// if lang is not in `Config.langs`it will fallback to `Config.default_lang` + /// if lang is not in `WebServer.langs`it will fallback to `Config.default_lang` #[must_use] pub fn lang(&self) -> String { #[allow(unused_assignments)] let mut lang = self.config().default_lang; let default_lang = self.config().default_lang; - let langs = self.config().langs; + let langs = self.websrvr().langs; // As fallback set default_lang lang = default_lang; // Get langs list from header @@ -295,7 +300,7 @@ impl ReqTasks { self .render_page( &mut ctx, - app_env.config.templates_path.as_str(), + app_env.get_curr_websrvr_config().templates_path.as_str(), template_name, fallback_template, data_path,