From f9a950d1c77bf3887999823b315d38854bcd1d72 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 20 Jan 2018 09:58:52 -0800 Subject: [PATCH] Default to production environment on non-debug builds. --- lib/src/config/environment.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/config/environment.rs b/lib/src/config/environment.rs index 3a154921..8c80107a 100644 --- a/lib/src/config/environment.rs +++ b/lib/src/config/environment.rs @@ -84,8 +84,13 @@ impl Environment { /// Returns a `BadEnv` `ConfigError` if `ROCKET_ENV` contains an invalid /// environment name. pub fn active() -> Result { - let env_str = env::var(CONFIG_ENV).unwrap_or(Development.to_string()); - env_str.parse().map_err(|_| ConfigError::BadEnv(env_str)) + match env::var(CONFIG_ENV) { + Ok(s) => s.parse().map_err(|_| ConfigError::BadEnv(s)), + #[cfg(debug_assertions)] + _ => Ok(Development), + #[cfg(not(debug_assertions))] + _ => Ok(Production), + } } /// Returns a string with a comma-seperated list of valid environments.