Default to production environment on non-debug builds.

This commit is contained in:
Sergio Benitez 2018-01-20 09:58:52 -08:00
parent 19f59b1f9b
commit f9a950d1c7
1 changed files with 7 additions and 2 deletions

View File

@ -84,8 +84,13 @@ impl Environment {
/// Returns a `BadEnv` `ConfigError` if `ROCKET_ENV` contains an invalid
/// environment name.
pub fn active() -> Result<Environment, ConfigError> {
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.