| 1 | use malice_static::{bind_listener, serve, static_router}; |
| 2 | |
| 3 | fn web_dir() -> Option<String> { |
| 4 | let dir = std::env::var("MALICE_WEB_DIR").ok()?; |
| 5 | assert!( |
| 6 | std::path::Path::new(&dir).join("index.html").is_file(), |
| 7 | "MALICE_WEB_DIR must point to built frontend assets containing index.html" |
| 8 | ); |
| 9 | Some(dir) |
| 10 | } |
| 11 | |
| 12 | #[tokio::main] |
| 13 | async fn main() { |
| 14 | tracing_subscriber::fmt() |
| 15 | .with_env_filter( |
| 16 | tracing_subscriber::EnvFilter::try_from_default_env() |
| 17 | .unwrap_or_else(|_| "malice_static=info,tower_http=info".into()), |
| 18 | ) |
| 19 | .with_target(false) |
| 20 | .compact() |
| 21 | .init(); |
| 22 | |
| 23 | let app = static_router(web_dir()); |
| 24 | serve(bind_listener().await, app, async {}).await; |
| 25 | } |