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