mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-29 15:49:16 +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 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
|
||||||
|
|
Loading…
Reference in a new issue