Compare commits
4 commits
main
...
fix_config
Author | SHA1 | Date | |
---|---|---|---|
4a9aef3646 | |||
cc84316600 | |||
15fe005eee | |||
83b65dd408 |
2 changed files with 7 additions and 7 deletions
2
docs/src/administration_configuration.md
vendored
2
docs/src/administration_configuration.md
vendored
|
@ -5,7 +5,7 @@ The configuration is based on the file
|
||||||
This file also contains documentation for all the available options. To override the defaults, you
|
This file also contains documentation for all the available options. To override the defaults, you
|
||||||
can copy the options you want to change into your local `config.hjson` file.
|
can copy the options you want to change into your local `config.hjson` file.
|
||||||
|
|
||||||
To use a different `config.hjson` location than the current directory, set the environment variable `LEMMY_CONFIG_LOCATION`.
|
To use a different `config.hjson` location than the current directory, set the environment variable `LEMMY_CONFIG_LOCATION`. Make sure you copy the `defaults.hjson` if you do this, otherwise you will be missing settings.
|
||||||
|
|
||||||
Additionally, you can override any config files with environment variables. These have the same
|
Additionally, you can override any config files with environment variables. These have the same
|
||||||
name as the config options, and are prefixed with `LEMMY_`. For example, you can override the
|
name as the config options, and are prefixed with `LEMMY_`. For example, you can override the
|
||||||
|
|
|
@ -81,9 +81,9 @@ impl Settings {
|
||||||
fn init() -> Result<Self, ConfigError> {
|
fn init() -> Result<Self, ConfigError> {
|
||||||
let mut s = Config::new();
|
let mut s = Config::new();
|
||||||
|
|
||||||
s.merge(File::with_name(CONFIG_FILE_DEFAULTS))?;
|
s.merge(File::with_name(&Self::get_config_defaults_location()))?;
|
||||||
|
|
||||||
s.merge(File::with_name(&Self::get_config_location()).required(false))?;
|
s.merge(File::with_name(CONFIG_FILE).required(false))?;
|
||||||
|
|
||||||
// Add in settings from the environment (with a prefix of LEMMY)
|
// Add in settings from the environment (with a prefix of LEMMY)
|
||||||
// Eg.. `LEMMY_DEBUG=1 ./target/app` would set the `debug` key
|
// Eg.. `LEMMY_DEBUG=1 ./target/app` would set the `debug` key
|
||||||
|
@ -115,16 +115,16 @@ impl Settings {
|
||||||
format!("{}/api/v1", self.hostname)
|
format!("{}/api/v1", self.hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_config_location() -> String {
|
pub fn get_config_defaults_location() -> String {
|
||||||
env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE.to_string())
|
env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE_DEFAULTS.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_config_file() -> Result<String, Error> {
|
pub fn read_config_file() -> Result<String, Error> {
|
||||||
fs::read_to_string(Self::get_config_location())
|
fs::read_to_string(CONFIG_FILE)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_config_file(data: &str) -> Result<String, Error> {
|
pub fn save_config_file(data: &str) -> Result<String, Error> {
|
||||||
fs::write(Self::get_config_location(), data)?;
|
fs::write(CONFIG_FILE, data)?;
|
||||||
|
|
||||||
// Reload the new settings
|
// Reload the new settings
|
||||||
// From https://stackoverflow.com/questions/29654927/how-do-i-assign-a-string-to-a-mutable-static-variable/47181804#47181804
|
// From https://stackoverflow.com/questions/29654927/how-do-i-assign-a-string-to-a-mutable-static-variable/47181804#47181804
|
||||||
|
|
Loading…
Reference in a new issue