atagen

malice

public
Star0
Watch0
294426c7f88fd4348a61b8a8590233237a1e52c0
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: crates/malice-static/src/main.rs

aa3dce5114d0atagen2026-10-26 06:09 UTC1
use std::sync::Arc;
aa3dce5114d0atagen2026-10-26 06:09 UTC2
aa3dce5114d0atagen2026-10-26 06:09 UTC3
use malice_static::{
aa3dce5114d0atagen2026-10-26 06:09 UTC4
    bind_listener,
aa3dce5114d0atagen2026-10-26 06:09 UTC5
    push::{Gateway, push_off_router, push_router},
aa3dce5114d0atagen2026-10-26 06:09 UTC6
    serve, static_router,
aa3dce5114d0atagen2026-10-26 06:09 UTC7
};
dffd63b58af4atagen2026-09-28 09:10 UTC8
dffd63b58af4atagen2026-09-28 09:10 UTC9
fn web_dir() -> Option<String> {
dffd63b58af4atagen2026-09-28 09:10 UTC10
    let dir = std::env::var("MALICE_WEB_DIR").ok()?;
dffd63b58af4atagen2026-09-28 09:10 UTC11
    assert!(
dffd63b58af4atagen2026-09-28 09:10 UTC12
        std::path::Path::new(&dir).join("index.html").is_file(),
dffd63b58af4atagen2026-09-28 09:10 UTC13
        "MALICE_WEB_DIR must point to built frontend assets containing index.html"
dffd63b58af4atagen2026-09-28 09:10 UTC14
    );
dffd63b58af4atagen2026-09-28 09:10 UTC15
    Some(dir)
dffd63b58af4atagen2026-09-28 09:10 UTC16
}
dffd63b58af4atagen2026-09-28 09:10 UTC17
dffd63b58af4atagen2026-09-28 09:10 UTC18
#[tokio::main]
dffd63b58af4atagen2026-09-28 09:10 UTC19
async fn main() {
dffd63b58af4atagen2026-09-28 09:10 UTC20
    tracing_subscriber::fmt()
dffd63b58af4atagen2026-09-28 09:10 UTC21
        .with_env_filter(
dffd63b58af4atagen2026-09-28 09:10 UTC22
            tracing_subscriber::EnvFilter::try_from_default_env()
dffd63b58af4atagen2026-09-28 09:10 UTC23
                .unwrap_or_else(|_| "malice_static=info,tower_http=info".into()),
dffd63b58af4atagen2026-09-28 09:10 UTC24
        )
dffd63b58af4atagen2026-09-28 09:10 UTC25
        .with_target(false)
dffd63b58af4atagen2026-09-28 09:10 UTC26
        .compact()
dffd63b58af4atagen2026-09-28 09:10 UTC27
        .init();
dffd63b58af4atagen2026-09-28 09:10 UTC28
aa3dce5114d0atagen2026-10-26 06:09 UTC29
    let app = match Gateway::from_env() {
aa3dce5114d0atagen2026-10-26 06:09 UTC30
        Some(gateway) => push_router(Arc::new(gateway)).merge(static_router(web_dir())),
aa3dce5114d0atagen2026-10-26 06:09 UTC31
        None => push_off_router().merge(static_router(web_dir())),
aa3dce5114d0atagen2026-10-26 06:09 UTC32
    };
dffd63b58af4atagen2026-09-28 09:10 UTC33
    serve(bind_listener().await, app, async {}).await;
dffd63b58af4atagen2026-09-28 09:10 UTC34
}