Add a use of route_service with ServeFile to the static-file-server example (#2361)

This commit is contained in:
Joel Uckelman 2023-11-27 14:49:54 +00:00 committed by GitHub
parent c9477282e7
commit 2e963cea9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,7 @@ async fn main() {
serve(using_serve_dir_with_handler_as_service(), 3004),
serve(two_serve_dirs(), 3005),
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) {
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();