fix: config loading order

This commit is contained in:
Aravinth Manivannan 2022-03-29 19:05:31 +05:30
parent c6f9cb7ac1
commit 1fe29fd9b2
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 17 additions and 7 deletions

View File

@ -16,6 +16,6 @@ port = 7000
#IP address. Enter 0.0.0.0 to listen on all availale addresses
ip= "0.0.0.0"
# The number of worker threads that must be spun up by the Pages server.
# Minimum of two threads are advisable for top async performace but can work
# Minimum of two threads are advisable for top async performance but can work
# with one also.
workers = 2

View File

@ -53,14 +53,24 @@ impl Settings {
const CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/static-pages/config.toml";
if let Ok(path) = env::var("PAGES__CONFIG") {
s = s.add_source(File::with_name(&path));
} else if Path::new(CURRENT_DIR).exists() {
let mut read_file = false;
if Path::new(ETC).exists() {
s = s.add_source(File::with_name(ETC));
read_file = true;
}
if Path::new(CURRENT_DIR).exists() {
// merging default config from file
s = s.add_source(File::with_name(CURRENT_DIR));
} else if Path::new(ETC).exists() {
s = s.add_source(File::with_name(ETC));
} else {
read_file = true;
}
if let Ok(path) = env::var("PAGES_CONFIG") {
s = s.add_source(File::with_name(&path));
read_file = true;
}
if !read_file {
log::warn!("configuration file not found");
}