1#![forbid(unsafe_code)]
2use color_eyre::Result;
3use tokio_util::sync::CancellationToken;
4
5#[cfg(feature = "mimalloc")]
6#[global_allocator]
7static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
8
9async fn spawn_axum_worker(
10 state: nailstate::ServerState,
11 shutdown_notifier: CancellationToken,
12) -> Result<()> {
13 let listener = nailnet::get_tcp_socket(&state.config.server.socket_addr)?;
14 let ip = listener.local_addr()?;
15
16 tracing::info!(
17 port = ip.port(),
18 address = ip.ip().to_string(),
19 "{} listening on {}",
20 std::thread::current().name().unwrap(),
21 ip
22 );
23
24 tokio::spawn(nailserve::serve(
25 listener,
26 nailroutes::nail_app(state),
27 shutdown_notifier,
28 ))
29 .await?
30}
31
32fn main() -> Result<()> {
33 color_eyre::install()?;
34
35 let config = nailconfig::get_configuration()?;
36
37 let inputs = nailpit::inputs::get_input_files(config.as_ref())?;
38
39 let templates = nailpit::inputs::get_template_files(config.as_ref())?;
40
41 let spicy = nailspicy::get_spicy_payload(config.as_ref());
42
43 nailrt::start(
44 nailstate::ServerState::new(config, inputs, templates, spicy),
45 spawn_axum_worker,
46 )?;
47
48 Ok(())
49}