atagen

malice

public
Star0
Watch0
bf301cf5de2f45d2453bb5cc8a28d8991b2c4cb5
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git
crates/malice-static/src/main.rsRust34 lines987 B
1
use std::sync::Arc;
2
3
use malice_static::{
4
    bind_listener,
5
    push::{Gateway, push_off_router, push_router},
6
    serve, static_router,
7
};
8
9
fn web_dir() -> Option<String> {
10
    let dir = std::env::var("MALICE_WEB_DIR").ok()?;
11
    assert!(
12
        std::path::Path::new(&dir).join("index.html").is_file(),
13
        "MALICE_WEB_DIR must point to built frontend assets containing index.html"
14
    );
15
    Some(dir)
16
}
17
18
#[tokio::main]
19
async fn main() {
20
    tracing_subscriber::fmt()
21
        .with_env_filter(
22
            tracing_subscriber::EnvFilter::try_from_default_env()
23
                .unwrap_or_else(|_| "malice_static=info,tower_http=info".into()),
24
        )
25
        .with_target(false)
26
        .compact()
27
        .init();
28
29
    let app = match Gateway::from_env() {
30
        Some(gateway) => push_router(Arc::new(gateway)).merge(static_router(web_dir())),
31
        None => push_off_router().merge(static_router(web_dir())),
32
    };
33
    serve(bind_listener().await, app, async {}).await;
34
}