-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ServeDir in nested route causes invalid redirects #1731
Comments
That seems like the only viable solution to me. It just feels wrong to move axum specific stuff into tower-http to solve an, arguably, axum bug. |
Yeah, this is definitely hard. We couldn't turn Maybe the best solution to be had is |
Yeah that might be the simplest solution. It would be great if it "just worked" but not sure how. |
Was |
It was removed because |
Have there been any updates on this? |
No I don't think so. |
This adds `FixNestedRedirectLayer` which uses `NestedPath` to change redirects from nested services to include the path they're nested at. Fixes #1731
My approach to solve this would be to have a ServeDir::with_mount_point() (see georgmu/tower-http@32512d3 - it is still in testing and not yet in form to create a pull request). This is still missing some mechanism to instantiate it without repeating the nested path in axum or reinsantiating ServeDir with every request... |
I've been putting together a middleware in axum to fix this #2230. Not quite there yet but that's another possible solution. |
@georgmu I like this patch and I know it isn't complete, but if it helps:
Not sure what the path forward is, but here's my fork that fits my needs when using axum: https://github.com/georgmu/tower-http/compare/serve-dir-mount-point...austenadler:tower-http:serve-dir-mount-point?expand=1 |
From my point of view, the problem is the design decision to alter the URI for nested routers. I think that with the presence of NestedPath, this altering is not necessary any more, but modifying this behavior would result in a breaking change and I don't know if this is wanted for other use cases |
Bug Report
Version
Platform
Linux yaya 6.1.7 #1-NixOS SMP PREEMPT_DYNAMIC Wed Jan 18 10:58:34 UTC 2023 x86_64 GNU/Linux
Description
https://yaya.yuka.dev/ is running a axum based webserver with a
axum::Router
. It has anest
route for/public
that contains aServeDir
service with path/mnt/public/
.Now, in
/mnt/public/
, there exists an empty directory/mnt/public/foo
.I request
https://yaya.yuka.dev/public/foo
And I get:
while I would have expected a redirect to
https://yaya.yuka.dev/public/foo/
This redirect is created here in ServeDir, and it uses the stripped path instead of the original uri to determine the redirect location.
Unsure how to solve this, but some ideas:
maybe the StripPrefix middleware and OriginalUri could be moved to tower_http and then tower_http can try to use the OriginalUri first and then fall back to the req.uri().
Or the nested route service could attempt to rewrite relative redirects, but that seems like it would not generally work since applications behind a reverse proxy could also have other ways of redirecting
Or ServeDir could be configured with a static prefix that is added to the redirects
The text was updated successfully, but these errors were encountered: