This commit is contained in:
Felipe Noronha 2022-03-12 12:48:31 -03:00
parent 3f341d9337
commit cd9a5053eb
2 changed files with 6 additions and 0 deletions

View File

@ -73,18 +73,23 @@ async fn handle(client_ip: IpAddr, req: Request<Body>) -> Result<Response<Body>,
debug_request(req)
}
}
#[tokio::main]
async fn main() {
let bind_addr = "127.0.0.1:8000";
let addr:SocketAddr = bind_addr.parse().expect("Could not parse ip:port.");
let make_svc = make_service_fn(|conn: &AddrStream| {
let remote_addr = conn.remote_addr().ip();
async move {
Ok::<_, Infallible>(service_fn(move |req| handle(remote_addr, req)))
}
});
let server = Server::bind(&addr).serve(make_svc);
println!("Running server on {:?}", addr);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}

View File

@ -83,6 +83,7 @@
//! let server = Server::bind(&addr).serve(make_svc);
//!
//! println!("Running server on {:?}", addr);
//!
//! if let Err(e) = server.await {
//! eprintln!("server error: {}", e);
//! }