blob: f65e4d42f1116eabf4c526dc4e65c6b3ab3190d0 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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(())
}
|