/
main.rs
38 lines (33 loc) · 1.13 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Run with
//!
//! ```not_rust
//! cd examples && cargo run -p example-customize-extractor-error
//! ```
mod custom_extractor;
mod derive_from_request;
mod with_rejection;
use axum::{routing::post, Router};
use std::net::SocketAddr;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() {
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(
std::env::var("RUST_LOG")
.unwrap_or_else(|_| "example_customize_extractor_error=trace".into()),
))
.with(tracing_subscriber::fmt::layer())
.init();
// Build our application with some routes
let app = Router::new()
.route("/with-rejection", post(with_rejection::handler))
.route("/custom-extractor", post(custom_extractor::handler))
.route("/derive-from-request", post(derive_from_request::handler));
// Run our application
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}