use std::env;
pub const ENV_VAR_CONFIG: &str = "TORRUST_IDX_BACK_CONFIG";
pub const ENV_VAR_CONFIG_PATH: &str = "TORRUST_IDX_BACK_CONFIG_PATH";
pub const ENV_VAR_CORS_PERMISSIVE: &str = "TORRUST_IDX_BACK_CORS_PERMISSIVE";
pub const ENV_VAR_DEFAULT_CONFIG_PATH: &str = "./config.toml";
use crate::config::Configuration;
pub async fn init_configuration() -> Configuration {
if env::var(ENV_VAR_CONFIG).is_ok() {
println!("Loading configuration from env var `{ENV_VAR_CONFIG}`");
Configuration::load_from_env_var(ENV_VAR_CONFIG).unwrap()
} else {
let config_path = env::var(ENV_VAR_CONFIG_PATH).unwrap_or_else(|_| ENV_VAR_DEFAULT_CONFIG_PATH.to_string());
println!("Loading configuration from config file `{config_path}`");
match Configuration::load_from_file(&config_path).await {
Ok(config) => config,
Err(error) => {
panic!("{}", error)
}
}
}
}