diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-08-24 23:07:13 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-08-24 23:07:13 +0200 |
commit | 14ab5ec766adf7e07a57d5ab63770f6c63df4af2 (patch) | |
tree | dd2cda70f2475f19b727aebd21010f83b85130d0 /src | |
parent | 87734ea6b0311903d42ed9ae55965bdf4ea13cb4 (diff) | |
download | ramaskrik-social-14ab5ec766adf7e07a57d5ab63770f6c63df4af2.tar.gz ramaskrik-social-14ab5ec766adf7e07a57d5ab63770f6c63df4af2.tar.bz2 ramaskrik-social-14ab5ec766adf7e07a57d5ab63770f6c63df4af2.zip |
Move database config to Rocket.toml.
This makes for one place to config everything instead of programatically
setting the config.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 14 | ||||
-rw-r--r-- | src/main.rs | 5 |
2 files changed, 3 insertions, 16 deletions
@@ -26,21 +26,11 @@ pub mod schema; use crate::controllers::{film, room, screening}; use rocket::routes; -use std::collections::HashMap; use std::error::Error; use std::result::Result; -pub fn build_rocket(db_url: &str) -> Result<rocket::Rocket, Box<dyn Error>> { - let mut db_config = HashMap::new(); - db_config.insert("url", rocket::config::Value::from(db_url)); - - let mut databases = HashMap::new(); - databases.insert("main", rocket::config::Value::from(db_config)); - - let mut config = rocket::Config::active()?; - config.extras.insert("databases".into(), rocket::config::Value::from(databases)); - - Ok(rocket::custom(config) +pub fn build_rocket() -> Result<rocket::Rocket, Box<dyn Error>> { + Ok(rocket::ignite() .attach(db::Connection::fairing()) .attach(rocket_contrib::templates::Template::fairing()) .mount("/", rocket_contrib::serve::StaticFiles::from("./public")) diff --git a/src/main.rs b/src/main.rs index 773fc66..fdc8ff3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,9 +21,6 @@ use std::error::Error; use std::result::Result; fn main() -> Result<(), Box<dyn Error>> { - let db_url = dotenv::var("DATABASE_URL") - .map_err(|_| "No database! Set DATABASE_URL env var and try again.")?; - - ramaskrik::build_rocket(&db_url)?.launch(); + ramaskrik::build_rocket()?.launch(); Ok(()) } |