diff --git a/src/main.rs b/src/main.rs index a6875bf..546fc9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ use actix_web::{ use crate::router::global; use json::JsonValue; use clap::Parser; -use std::sync::atomic::Ordering; fn unhandled(req: HttpRequest, body: String) -> Option { if body != String::new() { @@ -215,12 +214,15 @@ pub struct Args { https: bool } +pub fn get_args() -> Args { + Args::parse() +} + #[actix_web::main] async fn main() -> std::io::Result<()> { - let args = Args::parse(); + let args = get_args(); let port = args.port; - router::gree::HTTPS.store(args.https, Ordering::Relaxed); let rv = HttpServer::new(|| App::new() .wrap_fn(|req, srv| { println!("Request: {}", req.path()); diff --git a/src/router/gree.rs b/src/router/gree.rs index 148ca48..abcf4ba 100644 --- a/src/router/gree.rs +++ b/src/router/gree.rs @@ -7,8 +7,6 @@ use json::{object, JsonValue}; use hmac::{Hmac, Mac}; use rusqlite::params; use lazy_static::lazy_static; -use std::sync::atomic::Ordering; -use std::sync::atomic::AtomicBool; use openssl::pkey::PKey; use openssl::rsa::Rsa; @@ -333,12 +331,9 @@ pub fn migration_password_register(req: HttpRequest, body: String) -> HttpRespon send(req, resp) } -lazy_static!{ - pub static ref HTTPS: AtomicBool = AtomicBool::new(false); -} - pub fn get_protocol() -> String { - if HTTPS.load(Ordering::SeqCst) == true { + let args = crate::get_args(); + if args.https == true { return String::from("https"); } String::from("http") diff --git a/src/sql.rs b/src/sql.rs index 10f1fd6..9cc038a 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -1,7 +1,6 @@ use rusqlite::{Connection, params, ToSql}; use std::sync::Mutex; use json::{JsonValue, array}; -use clap::Parser; use std::fs; use crate::router::clear_rate::Live; @@ -13,7 +12,7 @@ pub struct SQLite { impl SQLite { pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite { - let args = crate::Args::parse(); + let args = crate::get_args(); fs::create_dir_all(&args.path).unwrap(); let conn = Connection::open(format!("{}/{}", args.path, path)).unwrap(); conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();