axum
axum copied to clipboard
Add `FixNestedRedirect` middleware
This adds FixNestedRedirectLayer which uses NestedPath to change redirects from nested services to include the path they're nested at.
Fixes #1731
Wouldn't it be better to fix this in tower-http? The current implementation in tower-http doesn't allow scenarios to use ServeDir with a prefix (e.g. /files/*). If such a mechanism would exist, a thin wrapper around ServeDir on axum side would fix this automatically.
Wouldn't it be better to fix this in tower-http?
That would require moving axum's NestedPath to tower-http or adding something similar there. I'm not a big fan of that.
FixNestedRedirectLayer is also useful when not using ServeDir.
Converting to draft because I just remember that this (and NestedPath) doesn't support path params in the nested path. axum supports .nest("/:foo", ...) which this should probably support.
Wouldn't it be better to fix this in tower-http?
That would require moving axum's
NestedPathto tower-http or adding something similar there. I'm not a big fan of that.
I wouldn't add NestedPath to tower-http, but give ServeDir the option to specify a "mount point" in the URL tree (like "files", so that GET /files/foo.txt would search for foo.txt, not files/foo.txt).
If ServeDir could do this, a thin wrapper around ServeDir in axum (let's call it NestedServeDir) could use the NestedPath mechanism to apply to instanciate ServeDir with the correct settings.
I'm a bit surprised this is in axum as opposed to axum-extra.
Yeah I considered putting it in axum-extra. That probably is the better path. I'll move it.
I wouldn't add NestedPath to tower-http, but give ServeDir the option to specify a "mount point" in the URL tree (like "files", so that GET /files/foo.txt would search for foo.txt, not files/foo.txt).
I think I'll move forward with the path in this PR and then see what happens as people use it and give feedback.