aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-01-11 23:17:19 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-01-11 23:17:19 +0100
commit49a06ccbf087c4ed0db3d61f3ac4892f45858ce1 (patch)
tree2173e4da34f793194c3f703160d981326681fc7b /src
parent0a7015b2b1d1e6682385ff3c02f14c1911158a8e (diff)
downloadrocket-blog-49a06ccbf087c4ed0db3d61f3ac4892f45858ce1.tar.gz
rocket-blog-49a06ccbf087c4ed0db3d61f3ac4892f45858ce1.tar.bz2
rocket-blog-49a06ccbf087c4ed0db3d61f3ac4892f45858ce1.zip
Read .env file in main.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs9
-rw-r--r--src/utils/mod.rs9
2 files changed, 9 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index be61d2d..4c05523 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,10 +18,17 @@ mod schema;
mod controllers;
use controllers::home_controller;
use controllers::posts_controller;
+use dotenv::dotenv;
+use std::env;
fn main() {
+ dotenv().expect("No .env file found.");
+
+ let dburl = env::var("DATABASE_URL")
+ .expect("DATABASE_URL environment variable must be set");
+
rocket::ignite()
- .manage(utils::init_db_pool())
+ .manage(utils::init_db_pool(&dburl))
.mount("/",
routes![
home_controller::index,
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 1d697fe..a1ece8b 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,20 +1,13 @@
use diesel::pg::PgConnection;
use r2d2;
use r2d2_diesel::ConnectionManager;
-use dotenv::dotenv;
-use std::env;
// An alias to the type for a pool of Diesel PostgreSql connections.
type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
/// Initializes a database pool.
-pub fn init_db_pool() -> Pool {
- dotenv().ok();
-
+pub fn init_db_pool<'a>(dburl: &'a str) -> Pool {
let config = r2d2::Config::default();
- let dburl = env::var("DATABASE_URL")
- .expect("DATABASE_URL environment variable must be set");
-
let manager = ConnectionManager::<PgConnection>::new(dburl);
r2d2::Pool::new(config, manager).expect("db pool")
}