summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: a1893b73a7fd443236e8227f19c6ac6d70ec6ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 tokio::net::TcpListener;
use tower_http::services::ServeFile;

pub async fn run() -> Result<()> {
    let config = config::Config::new()?;

    let app = 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.clone());

    let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), config.port);
    let listener = TcpListener::bind(socket).await?;

    axum::serve(listener, app).await?;

    Ok(())
}