Add method config::Config.public_path()
This commit is contained in:
parent
f1e38aa66f
commit
785cef1d3b
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Reference in New Issue