Parent [>]
1//! Binary entry point. Parses CLI arguments, initialises global configuration,
2//! builds the CSS theme, constructs the axum router, and starts the HTTP server.
3
4mod cli;
5
6use clap::Parser;
7use teak::config;
8use teak::theme::{BASE_CSS, MARKDOWN_CSS};
9use teak::{error, routes};
10
11#[tokio::main]
12async fn main() -> error::Result<()> {
13    let args = cli::Args::parse();
14
15    config::set_hostname(args.hostname);
16    config::set_ssh_prefix(args.ssh_prefix);
17    config::set_base_url(args.base_url);
18
19    let favicon_data = args.favicon.map_or_else(
20        || include_bytes!("../static/favicon.svg").to_vec(),
21        |path| std::fs::read(&path).unwrap_or_default(),
22    );
23    config::set_favicon(favicon_data);
24
25    let theme_vars = match args.theme_file {
26        Some(path) => std::fs::read_to_string(path)?,
27        None => args.theme.css().to_owned(),
28    };
29    let css = format!("{theme_vars}\n{BASE_CSS}\n{MARKDOWN_CSS}");
30
31    let state = routes::AppState {
32        root: args.root,
33        css,
34    };
35    let router = routes::router(state);
36    let addr = format!("{}:{}", args.bind, args.port);
37
38    let socket = tokio::net::TcpListener::bind(&addr).await?;
39    axum::serve(socket, router).await?;
40
41    Ok(())
42}