feat: modularize codebase and add multi-route support with live reload

This commit is contained in:
danielvici123
2026-06-08 21:27:11 +02:00
parent 56d3b0f9e0
commit 922b7170a4
8 changed files with 320 additions and 0 deletions

52
src/middleware.rs Normal file
View File

@@ -0,0 +1,52 @@
use axum::{
body::Body,
extract::{Request, State},
middleware::Next,
response::Response,
};
use chrono::Local;
use std::time::Instant;
use crate::state::SharedState;
// Note: Axum body might need to be imported differently depending on version
// but since the original used axum::body::Body, I'll stick to that or similar.
// Actually, let's use axum::body::Body.
pub async fn logging_middleware(
State(_state): State<SharedState>,
req: Request<Body>,
next: Next,
) -> Response {
let start_time = Local::now();
let start_instant = Instant::now();
// Load config live for masking settings
let config = crate::config::Config::load();
println!("---- REQUEST START {} ----", start_time.format("%Y-%m-%d %H:%M:%S"));
println!("Method: {}", req.method());
println!("Path: {}", req.uri().path());
println!("Headers:");
for (name, value) in req.headers() {
let name_str = name.as_str();
let should_mask = config.masking.enabled &&
config.masking.headers.iter().any(|h| h.eq_ignore_ascii_case(name_str));
if should_mask {
println!(" {}: ***", name_str);
} else {
println!(" {}: {:?}", name_str, value);
}
}
let response = next.run(req).await;
let end_time = Local::now();
let duration = start_instant.elapsed();
println!("--- REQUEST END {} - {:?} ---------", end_time.format("%H:%M:%S"), duration);
response
}