Skip to content

Commit

Permalink
Add a use of route_service with ServeFile to the static-file-server e…
Browse files Browse the repository at this point in the history
…xample (#2361)
  • Loading branch information
uckelman authored Nov 27, 2023
1 parent c947728 commit 2e963ce
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/static-file-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2e963ce

Please sign in to comment.