aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 3ad9efd..6135e97 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
#[macro_use] extern crate rocket;
-use std::collections::HashSet;
+use std::{collections::HashSet, process::exit};
use rocket::{http::Status, serde::json::Json, State};
use rocket_cors::CorsOptions;
@@ -292,7 +292,33 @@ fn rocket() -> _ {
};
let cors = cors.to_cors().unwrap();
- rocket::build().manage(Mutex::new(DB::load(Config::new())))
+ let mut config_path = "config.json".to_string();
+
+ let args: Vec<String> = std::env::args().collect();
+ for a in args {
+ let b: Vec<&str> = a.split('=').collect();
+ match b[0] {
+ "config" => {
+ config_path = b[1].to_string();
+ },
+ "genconfig" => {
+ Config::genconfig();
+ exit(0);
+ }
+ _ => ()
+ }
+ }
+
+ let config = match Config::load(config_path.into()) {
+ Ok(n) => n,
+ Err(_) => Config::new(),
+ };
+
+ let rocket_config = rocket::config::Config::figment()
+ .merge(("address", config.address()))
+ .merge(("port", config.port()));
+
+ rocket::custom(rocket_config).manage(Mutex::new(DB::load(&config)))
.mount("/", routes![index])
.mount("/user", routes![login, get_users_by_name, get_user_authenticated, get_user, new_user, get_all_users, logout, logout_all, get_sessions, delete])
.mount("/user/update", routes![update_name, update_password])