tower-rs / tower-http

HTTP specific Tower utilities.
680 stars 159 forks source link

ServerDir not accessing file #429

Closed greenpdx closed 10 months ago

greenpdx commented 10 months ago

Bug Report

Version v0.4.4

Platform ubuntu 22.04

Crates

tower-http = { version = "0.4.4", features = ["full"]}

Description

I am trying to server static files and access the using firefox/ chromium ServeFile works disabled cache

I tried this code: route/srvdir.rs pub fn create_route() -> Router { let service = ServeDir::new("dist"); //.append_index_html_on_directories(false); //.fallback(ServeFile::new("/Cargo.toml"));

Router::new().route_service("/vue/", service)

} app.rs Router::new() .merge(routes::status::create_route()) .merge(routes::user::create_route()) .merge(routes::srvdir::create_route()) .merge(Router::new().nest(

/ routes/ pub mod cat; pub mod status; pub mod user; pub mod srvdir;

I have tried. (dots not included) ServeDir......route_service.....URL.......................result dist............./vue....................../vue/bob.html....404 dist............./vue/....................../vue/bob.html....404 dist/............./vue....................../vue/bob.html....404 dist/............./vue/..................../vue/bob.html....404 dist............./vue....................../dist/bob.html....404

example please

davidpdrsn commented 10 months ago

Use nest_service, not route_service.

There are plenty of examples in the axum repo.