Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Example environment configuration for Valence
# Copy to .env and adjust values as needed

DEBUG=true
EXTERN_PORT=8081

DB_PROTOCOL=mongodb://
DB_URL=localhost
DB_PORT=27017
DB_USER=root
DB_PASSWORD=example

CACHE_URL=redis://localhost
CACHE_PORT=6379
CACHE_PASSWORD=secret

BODY_LIMIT=8192
CACHE_TTL=900

MARKET=false
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
async-trait = "0.1.73"
chrono = "0.4.26"
config = "0.13.3"
dotenvy = "0.15.7"
cuckoofilter = "0.5.0"
futures = "0.3.28"
hex = "0.4.3"
Expand Down
10 changes: 8 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ pub async fn init_cuckoo_filter<T: KvStoreConnection>(

/// Loads the config file
pub fn load_config() -> EnvConfig {
let settings = config::Config::builder().add_source(config::File::with_name(CONFIG_FILE));
// Load variables from a .env file into process environment if present
dotenvy::dotenv().ok();

// File-sourced config first, then environment with higher precedence
let settings = config::Config::builder()
.add_source(config::File::with_name(CONFIG_FILE))
.add_source(config::Environment::default());

match settings.build() {
Ok(config) => EnvConfig {
Expand All @@ -183,7 +189,7 @@ pub fn load_config() -> EnvConfig {
.unwrap_or(SETTINGS_DB_URL.to_string()),
db_user: config
.get_string("db_user")
.unwrap_or(SETTINGS_DB_URL.to_string()),
.unwrap_or(SETTINGS_DB_USER.to_string()),
db_protocol: config
.get_string("db_protocol")
.unwrap_or(SETTINGS_DB_PROTOCOL.to_string()),
Expand Down
Loading