From 5e93ce258f2ca8e4b5d1d4b2b2c0ecc61c6a4e67 Mon Sep 17 00:00:00 2001 From: Alexey <247128645+axkurcom@users.noreply.github.com> Date: Wed, 4 Mar 2026 01:08:42 +0300 Subject: [PATCH] API pull-up Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com> --- src/main.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main.rs b/src/main.rs index f7f9239..7a775d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use tracing_subscriber::{EnvFilter, fmt, prelude::*, reload}; use tokio::net::UnixListener; mod cli; +mod api; mod config; mod crypto; mod error; @@ -1152,6 +1153,36 @@ async fn main() -> std::result::Result<(), Box> { }); } + if config.server.api.enabled { + let listen = match config.server.api.listen.parse::() { + Ok(listen) => listen, + Err(error) => { + warn!( + error = %error, + listen = %config.server.api.listen, + "Invalid server.api.listen; API is disabled" + ); + SocketAddr::from(([127, 0, 0, 1], 0)) + } + }; + if listen.port() != 0 { + let stats = stats.clone(); + let ip_tracker_api = ip_tracker.clone(); + let config_rx_api = config_rx.clone(); + let config_path_api = std::path::PathBuf::from(&config_path); + tokio::spawn(async move { + api::serve( + listen, + stats, + ip_tracker_api, + config_rx_api, + config_path_api, + ) + .await; + }); + } + } + for (listener, listener_proxy_protocol) in listeners { let mut config_rx: tokio::sync::watch::Receiver> = config_rx.clone(); let stats = stats.clone();