diff options
Diffstat (limited to 'server/src/main.rs')
-rw-r--r-- | server/src/main.rs | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 94a53c7..ea75208 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -8,45 +8,65 @@ #![recursion_limit = "4096"] use anyhow::Context; +use config::load_config; use database::Database; -use jellybase::{federation::Federation, CONF, SECRETS}; -use jellylogic::{admin::log::enable_logging, login::hash_password}; +use jellylogic::{admin::log::enable_logging, login::create_admin_account}; use log::{error, info, warn}; use routes::build_rocket; -use tokio::fs::create_dir_all; +use serde::{Deserialize, Serialize}; +use std::sync::Mutex; +use std::{path::PathBuf, process::exit, sync::LazyLock}; pub use jellybase::database; pub mod api; pub mod compat; +pub mod config; pub mod helper; pub mod locale; pub mod logic; pub mod routes; pub mod ui; +#[rustfmt::skip] +#[derive(Debug, Deserialize, Serialize, Default)] +pub struct Config { + database_path: PathBuf, + asset_path: PathBuf, + cookie_key: Option<String>, + tls:bool, + hostname: String, +} + +pub static CONF_PRELOAD: Mutex<Option<Config>> = Mutex::new(None); +static CONF: LazyLock<Config> = LazyLock::new(|| { + CONF_PRELOAD + .lock() + .unwrap() + .take() + .expect("cache config not preloaded. logic error") +}); + #[rocket::main] async fn main() { enable_logging(); + info!("loading config..."); + if let Err(e) = load_config().await { + error!("error {e:?}"); + exit(1); + } + #[cfg(feature = "bypass-auth")] log::warn!("authentification bypass enabled"); - create_dir_all(&CONF.cache_path).await.unwrap(); let database = Database::open(&CONF.database_path) .context("opening database") .unwrap(); - let federation = Federation::initialize(); - if let Some(username) = &CONF.admin_username - && let Some(password) = &SECRETS.admin_password - { - database - .create_admin_user(username, hash_password(username, password)) - .unwrap(); - } else { - info!("admin account disabled") + if let Err(e) = create_admin_account(&database) { + error!("failed to create admin account: {e:?}"); } - let r = build_rocket(database, federation).launch().await; + let r = build_rocket(database).launch().await; match r { Ok(_) => warn!("server shutdown"), Err(e) => error!("server exited: {e}"), |