michalvankodev-site/axum_server/src/router.rs

39 lines
1.4 KiB
Rust
Raw Normal View History

2024-01-30 22:19:36 +01:00
use crate::{
feed::render_rss_feed,
2024-04-25 23:05:47 +02:00
pages::{
2024-05-09 23:26:06 +02:00
admin::render_admin, contact::render_contact, index::render_index, post::render_post,
2024-04-25 23:05:47 +02:00
post_list::render_post_list,
},
2024-01-30 22:19:36 +01:00
};
2024-01-09 20:54:36 +01:00
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()
2024-01-11 20:43:47 +01:00
.route("/", get(render_index))
2024-01-14 22:56:14 +01:00
.route("/blog", get(render_post_list))
2024-01-16 21:56:29 +01:00
.route("/blog/tags/:tag", get(render_post_list))
2024-01-11 22:16:38 +01:00
.route("/blog/:post_id", get(render_post))
2024-04-25 23:05:47 +02:00
.route("/contact", get(render_contact))
2024-05-09 23:26:06 +02:00
.route("/admin", get(render_admin))
2024-01-30 22:19:36 +01:00
.route("/feed.xml", get(render_rss_feed))
2024-01-09 20:54:36 +01:00
.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,
)
}),
)
}