Closed avalon1610 closed 3 years ago
MakeService
is not required to serve services. SocketAddr
is added by Request
extensions so you can get it like:
use axum::{extract::Extension, handler::get, Router};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(handler));
axum_server::bind("127.0.0.1:3000")
.serve(app)
.await
.unwrap();
}
async fn handler(Extension(addr): Extension<SocketAddr>) -> String {
format!("addr: {}", addr)
}
I should probably document it better.
Added this example.
why I get error "500 : Missing request extension: Extension of type core::net::socket_addr::SocketAddr
was not found. Perhaps you forgot to add it? See axum::Extension
."
@3tieto The example you are looking is from 0.2
version of this crate. Check this up to date example.
for use
axum::extract::ConnectInfo
, we need into_make_service_with_connect_info.which is not supported in axum-server for now.
we got