Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Axum Tower ServeDir not serving from subdirectories
I've got a monorepo of Axum as server and a Vite app as frontend. Vite bundles some resources in ui/dist
directory like this:
img/
fonts/
assets/
index.html
I'm trying to serve this directory with ServeDir
like:
let serve_dir = ServeDir::new("ui/dist");
let rest_routes = rest_api::get_router(app_state);
let app = Router::new()
.route("/", get_service(serve_dir))
.nest("/api", rest_routes);
But except index.html
I get 404s from anything under subdirectories like img
, fonts
.
I'm confused because ServeDir
docs point out it should work with subdirectories.
Individual subdirs start working if I add:
let serve_assets = ServeDir::new("ui/dist/assets");
and
let app = Router::new()
.route("/", get_service(serve_dir))
.nest("/api", rest_routes)
.nest_service("/assets", serve_assets);
When I add a capture everything goes 404 including index.html
:
.route("/{anything_goes}", get_service(serve_dir))
I checked this Axum example in Github, but I'm not sure it fits my use case with index.html
at the root and subdirectory resources.
Do I have to add every subdirectory as a different service and use nest_service
?
1 post - 1 participant
🏷️ Rust_feed