diff --git a/src/main.rs b/src/main.rs index 7d4d9b3..c223887 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,10 +7,10 @@ use crate::servers::Server; use log::{debug, error}; use std::env; +use std::path::Path; fn main() { - let config_path = - env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string()); + let config_path = find_config(); let config = match Config::new(&config_path) { Ok(config) => config, @@ -27,3 +27,18 @@ fn main() { let _ = server.run(); error!("Server ended with errors"); } + +fn find_config() -> String { + let config_path = + env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string()); + + if Path::new(&config_path).exists() { + return config_path; + } + + if Path::new("config.yaml").exists() { + return String::from("config.yaml"); + } + + String::from("") +}