aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs42
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.");
+ };
}