From 19979216185894d99a108adcc8e3d356a5979dd4 Mon Sep 17 00:00:00 2001 From: curly Date: Wed, 17 Jul 2024 19:25:00 -0600 Subject: config --- src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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 = 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]) -- cgit v1.2.3