main.rs
This file
Path
examples/compression/src/main.rs
39 lines · 1.1 KiB · Rust
Last changed by
Fix return types of serve futures (#3601)Jonas Plattebefore adoptionf3a95d7
History of this fileTake it
The walk stopped after 200 commits: lines older than dcbcf5c point at it.
axum-extra: Make typed-routing feature enable routing feature (#3514)tottotobefore adoptiondcbcf5c
lines 1–25why, one step back1use axum::{routing::post, Json, Router};2use serde_json::Value;3use tower::ServiceBuilder;4use tower_http::{compression::CompressionLayer, decompression::RequestDecompressionLayer};5use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};67#[cfg(test)]8mod tests;910#[tokio::main]11async fn main() {12 tracing_subscriber::registry()13 .with(14 tracing_subscriber::EnvFilter::try_from_default_env()15 .unwrap_or_else(|_| format!("{}=trace", env!("CARGO_CRATE_NAME")).into()),16 )17 .with(tracing_subscriber::fmt::layer())18 .init();1920 let app: Router = app();2122 let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")23 .await24 .unwrap();25 tracing::debug!("listening on {}", listener.local_addr().unwrap());Fix return types of serve futures (#3601)Jonas Plattebefore adoptionf3a95d7
line 26why, one step back26 axum::serve(listener, app).await;axum-extra: Make typed-routing feature enable routing feature (#3514)tottotobefore adoptiondcbcf5c
lines 27–39why, one step back27}2829fn app() -> Router {30 Router::new().route("/", post(root)).layer(31 ServiceBuilder::new()32 .layer(RequestDecompressionLayer::new())33 .layer(CompressionLayer::new()),34 )35}3637async fn root(Json(value): Json<Value>) -> Json<Value> {38 Json(value)39}