From cbb2e8a2440487a33297c8bbdde52b9e75ed5f5b Mon Sep 17 00:00:00 2001 From: Shing <5630513+yshing@users.noreply.github.com> Date: Wed, 15 Jun 2022 16:04:44 +0800 Subject: [PATCH] Fix missing assets in websockets example (#1089) * fix missing assets running websockets example * Update examples/websockets/src/main.rs Co-authored-by: David Pedersen * remove unnecessary mut * fix cargo fmt Co-authored-by: David Pedersen --- examples/websockets/src/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/websockets/src/main.rs b/examples/websockets/src/main.rs index 9dab67a0..b221810c 100644 --- a/examples/websockets/src/main.rs +++ b/examples/websockets/src/main.rs @@ -32,19 +32,17 @@ async fn main() { )) .with(tracing_subscriber::fmt::layer()) .init(); - + let assets_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets"); // build our application with some routes let app = Router::new() .fallback( - get_service( - ServeDir::new("examples/websockets/assets").append_index_html_on_directories(true), - ) - .handle_error(|error: std::io::Error| async move { - ( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Unhandled internal error: {}", error), - ) - }), + get_service(ServeDir::new(assets_dir).append_index_html_on_directories(true)) + .handle_error(|error: std::io::Error| async move { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Unhandled internal error: {}", error), + ) + }), ) // routes are matched from bottom to top, so we have to put `nest` at the // top since it matches all routes