aboutsummaryrefslogtreecommitdiff
path: root/server/src/main.rs
blob: 30b80edbbeac7c17b57272af506f8dbd1a309964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2025 metamuffin <metamuffin.org>
*/
#![feature(
    int_roundings,
    let_chains,
    str_as_str,
    duration_constructors,
    duration_constructors_lite
)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![recursion_limit = "4096"]

use config::load_config;
use jellylogic::{admin::log::enable_logging, login::create_admin_account};
use log::{error, info, warn};
use routes::build_rocket;
use serde::{Deserialize, Serialize};
use std::sync::Mutex;
use std::{path::PathBuf, process::exit, sync::LazyLock};

pub mod api;
pub mod compat;
pub mod config;
pub mod helper;
pub mod logic;
pub mod routes;
pub mod ui;

#[rustfmt::skip]
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct Config {
    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");

    if let Err(e) = create_admin_account() {
        error!("failed to create admin account: {e:?}");
    }

    let r = build_rocket().launch().await;
    match r {
        Ok(_) => warn!("server shutdown"),
        Err(e) => error!("server exited: {e}"),
    }
}