mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-25 00:28:07 +01:00
Add a use of route_service with ServeFile to the static-file-server example (#2361)
This commit is contained in:
parent
c9477282e7
commit
2e963cea9d
1 changed files with 5 additions and 0 deletions
|
@ -32,6 +32,7 @@ async fn main() {
|
||||||
serve(using_serve_dir_with_handler_as_service(), 3004),
|
serve(using_serve_dir_with_handler_as_service(), 3004),
|
||||||
serve(two_serve_dirs(), 3005),
|
serve(two_serve_dirs(), 3005),
|
||||||
serve(calling_serve_dir_from_a_handler(), 3006),
|
serve(calling_serve_dir_from_a_handler(), 3006),
|
||||||
|
serve(using_serve_file_from_a_route(), 3307),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +102,10 @@ fn calling_serve_dir_from_a_handler() -> Router {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn using_serve_file_from_a_route() -> Router {
|
||||||
|
Router::new().route_service("/foo", ServeFile::new("assets/index.html"))
|
||||||
|
}
|
||||||
|
|
||||||
async fn serve(app: Router, port: u16) {
|
async fn serve(app: Router, port: u16) {
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], port));
|
let addr = SocketAddr::from(([127, 0, 0, 1], port));
|
||||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue