Revert hello_world example

Accidentally changed it while testing something
This commit is contained in:
David Pedersen 2021-08-10 10:03:29 +02:00
parent 8ef96f2199
commit 594052dc48

View file

@ -1,24 +1,26 @@
//! Run with
//!
//! ```not_rust
//! cargo run --example hello_world
//! ```
use axum::prelude::*; use axum::prelude::*;
use std::{convert::Infallible, net::SocketAddr, time::Duration}; use std::net::SocketAddr;
use tower::{limit::RateLimitLayer, BoxError, ServiceBuilder};
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let handler_layer = ServiceBuilder::new() // Set the RUST_LOG, if it hasn't been explicitly defined
.buffer(1024) if std::env::var("RUST_LOG").is_err() {
.layer(RateLimitLayer::new(10, Duration::from_secs(10))) std::env::set_var("RUST_LOG", "hello_world=debug")
.into_inner(); }
tracing_subscriber::fmt::init();
let app = route( // build our application with a route
"/", let app = route("/", get(handler));
get(handler
.layer(handler_layer)
.handle_error(|error: BoxError| {
Ok::<_, Infallible>(format!("Unhandled error: {}", error))
})),
);
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr) axum::Server::bind(&addr)
.serve(app.into_make_service()) .serve(app.into_make_service())
.await .await