mod args; mod config; mod errors; mod handlers; mod models; pub use errors::{Error, Result}; use std::net::{IpAddr, Ipv6Addr, SocketAddr}; use axum::{Router, routing::get}; use clap::Parser; use tokio::net::TcpListener; use tower_http::services::ServeFile; use args::{Cli, Command}; use config::Config; pub fn app(config: Config) -> Router { Router::new() .nest_service("/static/style.css", ServeFile::new(&config.style_file)) .nest_service("/static/favicon.svg", ServeFile::new(&config.favicon_file)) .route("/", get(handlers::handler)) .with_state(config) } pub async fn run() -> Result<()> { let args = Cli::parse(); match args.command { Command::Serv(args) => { let config = config::Config::new(args)?; let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), config.port); let listener = TcpListener::bind(socket).await?; axum::serve(listener, app(config.clone())).await?; } } Ok(()) }