first refactor
This commit is contained in:
27
axum_server/src/router.rs
Normal file
27
axum_server/src/router.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use crate::post_parser::parse_post;
|
||||
use axum::{extract::MatchedPath, http::Request, routing::get, Router};
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::info_span;
|
||||
|
||||
pub fn get_router() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(|| async { "Hello, World!" }))
|
||||
.route("/blog/:post_id", get(parse_post))
|
||||
.layer(
|
||||
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
|
||||
// Log the matched route's path (with placeholders not filled in).
|
||||
// Use request.uri() or OriginalUri if you want the real path.
|
||||
let matched_path = request
|
||||
.extensions()
|
||||
.get::<MatchedPath>()
|
||||
.map(MatchedPath::as_str);
|
||||
|
||||
info_span!(
|
||||
"http_request",
|
||||
method = ?request.method(),
|
||||
matched_path,
|
||||
some_other_field = tracing::field::Empty,
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user