Open Pistonight opened 11 months ago
Nesting is a concept of axum, not tower / tower-http. This is tracked at https://github.com/tokio-rs/axum/issues/1731.
Unfortunately, this goes beyond axum. ServeDir
generally doesn’t support being mounted into a subdirectory which limits its usefulness considerably. This can only be fixed by messing with the redirects produced by ServeDir
which is quite frankly a very ugly hack.
Yeah, I've thought a bunch about this in the meantime and I think it's probably much easier (and useful beyond axum) to add some prefix to ServeDir
(maybe optionally stripping it from the input path, depending on whether you're already using sth. like nesting that does it up-front).
I have created a PR: #486
Bug Report
Version
tower-http v0.4.4
Platform
All
Description
This function redirects paths that don't end with
/
and is a directory to the URI with/
appended https://github.com/tower-rs/tower-http/blob/e8eb54966604ea7fa574a2a25e55232f5cfe675b/tower-http/src/services/fs/serve_dir/open_file.rs#L253However it does not take into account where the service could be nested, therefore producing an invalid redirect.
Example directory:
main.rs:
Going to
localhost:3000/src/hello
to see the issue Expected: Redirects tolocalhost:3000/src/hello/
and returns content atsrc/hello/index.html
Actual: Redirects tolocalhost:3000/hello/
and returns Not Found