logging ig

This commit is contained in:
Zynh0722 2023-04-13 11:49:13 -07:00
parent abf88d8656
commit 4d12dfd7e0

View file

@ -2,9 +2,10 @@ use async_zip::tokio::write::ZipFileWriter;
use async_zip::{Compression, ZipEntryBuilder}; use async_zip::{Compression, ZipEntryBuilder};
use axum::body::StreamBody; use axum::body::StreamBody;
use axum::extract::State; use axum::extract::{ConnectInfo, State};
use axum::http::StatusCode; use axum::http::{Request, StatusCode};
use axum::response::IntoResponse; use axum::middleware::{Next, self};
use axum::response::{IntoResponse, Response};
use axum::routing::{get, post}; use axum::routing::{get, post};
use axum::{ use axum::{
extract::{DefaultBodyLimit, Multipart}, extract::{DefaultBodyLimit, Multipart},
@ -74,19 +75,26 @@ async fn main() -> io::Result<()> {
)) ))
.with_state(state) .with_state(state)
.nest_service("/", ServeDir::new("dist")) .nest_service("/", ServeDir::new("dist"))
.layer(TraceLayer::new_for_http()); .layer(TraceLayer::new_for_http())
.layer(middleware::from_fn(log_source));
// Server creation // Server creation
let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
tracing::debug!("listening on http://{}/", addr); tracing::debug!("listening on http://{}/", addr);
axum::Server::bind(&addr) axum::Server::bind(&addr)
.serve(app.into_make_service()) .serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await .await
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
async fn log_source<B>(ConnectInfo(addr): ConnectInfo<SocketAddr>, req: Request<B>, next: Next<B>) -> Response {
tracing::info!("{}", addr);
next.run(req).await
}
async fn upload_to_zip( async fn upload_to_zip(
State(state): State<AppState>, State(state): State<AppState>,
mut body: Multipart, mut body: Multipart,