1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-04-26 13:56:22 +02:00

Fix missing assets in websockets example ()

* fix missing assets running websockets example

* Update examples/websockets/src/main.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* remove unnecessary mut

* fix cargo fmt

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
Shing 2022-06-15 16:04:44 +08:00 committed by GitHub
parent ad67289226
commit cbb2e8a244
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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