mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-18 00:00:15 +02:00
Add a use of route_service with ServeFile to the static-file-server example (#2361)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user