aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-24 23:07:13 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-24 23:07:13 +0200
commit14ab5ec766adf7e07a57d5ab63770f6c63df4af2 (patch)
treedd2cda70f2475f19b727aebd21010f83b85130d0 /src
parent87734ea6b0311903d42ed9ae55965bdf4ea13cb4 (diff)
downloadramaskrik-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.rs14
-rw-r--r--src/main.rs5
2 files changed, 3 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 57d8b7a..330c462 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(())
}