aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Rocket.toml.example32
-rw-r--r--src/lib.rs14
-rw-r--r--src/main.rs5
3 files changed, 35 insertions, 16 deletions
diff --git a/Rocket.toml.example b/Rocket.toml.example
new file mode 100644
index 0000000..9dbee4a
--- /dev/null
+++ b/Rocket.toml.example
@@ -0,0 +1,32 @@
+[global.databases]
+# Change the database url for your setup
+main = { url = "postgres:///...." }
+
+[development]
+address = "localhost"
+port = 8000
+workers = 2
+keep_alive = 5
+log = "normal"
+limits = { forms = 32768 }
+
+[staging]
+address = "0.0.0.0"
+port = 8000
+workers = 2
+keep_alive = 5
+log = "normal"
+# You have to generate a secret key, f.eks by `openssl rand -base64 32`.
+# Resetting this value will invalidate any cookies etc.
+secret_key = ...
+limits = { forms = 32768 }
+
+[production]
+address = "0.0.0.0"
+port = 8000
+keep_alive = 5
+log = "critical"
+# You have to generate a secret key, f.eks by `openssl rand -base64 32`.
+# Resetting this value will invalidate any cookies etc.
+secret_key = ...
+limits = { forms = 32768 }
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(())
}