1
0
Fork 0

Add method config::Config.public_path()

This commit is contained in:
Alex Kotov 2020-10-15 23:55:10 +05:00
parent f1e38aa66f
commit 785cef1d3b
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 14 additions and 0 deletions

View File

@ -105,6 +105,19 @@ impl Config {
.port(self.port)
}
pub fn public_path(&self) -> Result<String, ()> {
let mut result_path_buf = std::path::PathBuf::new();
result_path_buf.push(self.root.to_string());
result_path_buf.push("public");
let result_str = match result_path_buf.to_str() {
None => return Err(()),
Some(value) => value,
};
Ok(result_str.to_string())
}
pub fn use_env_for_root(&mut self) {
self.root = match std::env::var("ROOT") {
Err(_) => return,

View File

@ -20,5 +20,6 @@ fn main() {
dotenv::dotenv().unwrap();
let config = config::Config::from_env().unwrap();
println!("Running with {:#?}", config);
println!("Public path: {:#?}", config.public_path().unwrap());
web::rocket(config).launch();
}