diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-01-14 15:20:03 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-01-14 15:32:49 +0100 |
commit | 47e46a6e00c47622e99cfd65083887b3dce02716 (patch) | |
tree | 82940c31b56fd7eb8b32745b89d5789f82af26b5 /src | |
parent | bec84a39f3ace0c4803ce392eef9c0877fab9629 (diff) | |
download | rocket-blog-47e46a6e00c47622e99cfd65083887b3dce02716.tar.gz rocket-blog-47e46a6e00c47622e99cfd65083887b3dce02716.tar.bz2 rocket-blog-47e46a6e00c47622e99cfd65083887b3dce02716.zip |
Improve error message with missing database url.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index bdb8524..4e96a65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,28 +18,26 @@ 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(&dburl)) - .mount("/", - routes![ - home_controller::index, - home_controller::index_json]) - .mount("/posts", - routes![ - posts_controller::new, - posts_controller::create, - posts_controller::show, - posts_controller::edit, - posts_controller::update, - posts_controller::delete]) - .launch(); + if let Ok(dburl) = dotenv::var("DATABASE_URL") { + rocket::ignite() + .manage(utils::init_db_pool(&dburl)) + .mount("/", + routes![ + home_controller::index, + home_controller::index_json]) + .mount("/posts", + routes![ + posts_controller::new, + posts_controller::create, + posts_controller::show, + posts_controller::edit, + posts_controller::update, + posts_controller::delete]) + .launch(); + } + else { + eprintln!("Error: No database specified, make sure the DATABASE_URL env var is set."); + }; } |