Skip to content

Commit 8a61fc2

Browse files
committed
Require SSL on Heroku
1 parent 0296ec4 commit 8a61fc2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/db.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ pub fn pool(url: &str, config: r2d2::Config<postgres::Connection, r2d2_postgres:
103103
}
104104

105105
pub fn diesel_pool(url: &str, config: r2d2::Config<PgConnection, r2d2_diesel::Error>) -> DieselPool {
106-
let manager = ConnectionManager::new(url);
106+
let mut url = Url::parse(url).expect("Invalid database URL");
107+
if env::var("HEROKU").is_ok() && !url.query_pairs().any(|(k, v)| k == "sslmode") {
108+
url.query_pairs_mut().append_pair("sslmode", "require");
109+
}
110+
let manager = ConnectionManager::new(&url.into_string());
107111
r2d2::Pool::new(config, manager).unwrap()
108112
}
109113

0 commit comments

Comments
 (0)