mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-28 23:38:20 +01:00
Revert hello_world example
Accidentally changed it while testing something
This commit is contained in:
parent
8ef96f2199
commit
594052dc48
1 changed files with 16 additions and 14 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue