mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
When env variable is set, any config file will be ignored and the default settings will be used (#4594)
* do not panic when no config file found use defaults * formatting * implement env variable * ermove commented code * remove redundant comment * remove redundant space * simplify check logic * format * returns and messages * correct mistake
This commit is contained in:
parent
705e86eb4c
commit
a14ebefd24
@ -13,8 +13,17 @@ use structs::{DatabaseConnection, PictrsConfig, PictrsImageMode, Settings};
|
||||
static DEFAULT_CONFIG_FILE: &str = "config/config.hjson";
|
||||
|
||||
pub static SETTINGS: Lazy<Settings> = Lazy::new(|| {
|
||||
Settings::init().expect("Failed to load settings file, see documentation (https://join-lemmy.org/docs/en/administration/configuration.html)")
|
||||
if env::var("LEMMY_INITIALIZE_WITH_DEFAULT_SETTINGS").is_ok() {
|
||||
println!(
|
||||
"LEMMY_INITIALIZE_WITH_DEFAULT_SETTINGS was set, any configuration file has been ignored."
|
||||
);
|
||||
println!("Use with other environment variables to configure this instance further; e.g. LEMMY_DATABASE_URL.");
|
||||
Settings::default()
|
||||
} else {
|
||||
Settings::init().expect("Failed to load settings file, see documentation (https://join-lemmy.org/docs/en/administration/configuration.html).")
|
||||
}
|
||||
});
|
||||
|
||||
static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(&format!(
|
||||
"^acct:([a-zA-Z0-9_]{{3,}})@{}$",
|
||||
@ -30,9 +39,7 @@ impl Settings {
|
||||
/// `lemmy_db_schema/src/lib.rs::get_database_url_from_env()`
|
||||
/// Warning: Only call this once.
|
||||
pub(crate) fn init() -> Result<Self, LemmyError> {
|
||||
// Read the config file
|
||||
let config = from_str::<Settings>(&Self::read_config_file()?)?;
|
||||
|
||||
if config.hostname == "unset" {
|
||||
Err(anyhow!("Hostname variable is not set!").into())
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user