From 64c974bdc7281521ae205c2d0d55312c76357700 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Fri, 18 Aug 2023 01:15:40 +0300 Subject: [PATCH] log of connections to neaccount --- ngaccount/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ngaccount/src/main.rs b/ngaccount/src/main.rs index 72579d4..c2853fc 100644 --- a/ngaccount/src/main.rs +++ b/ngaccount/src/main.rs @@ -260,6 +260,21 @@ async fn main() -> anyhow::Result<()> { .allow_methods(vec!["GET"]) .allow_headers(vec!["Content-Type"]); + let incoming_log = warp::log::custom(|info| { + if info.remote_addr().is_some() { + log_info!( + "{:?} {} {}", + info.request_headers() + .get("X-Forwarded-For") + .map(|x| x.to_str().unwrap()) + .unwrap_or(info.remote_addr().unwrap().to_string().as_str()), + //info.remote_addr().unwrap(), + info.method(), + info.path() + ); + } + }); + #[cfg(not(debug_assertions))] { let origin = format!("https://{}", domain); @@ -276,7 +291,7 @@ async fn main() -> anyhow::Result<()> { log_debug!("CORS: any origin"); cors = cors.allow_any_origin(); log::info!("Starting server on http://192.168.192.2:3031"); - warp::serve(api_v1.or(static_files).with(cors)) + warp::serve(api_v1.or(static_files).with(cors).with(incoming_log)) .run(([192, 168, 192, 2], 3031)) .await; }