0.35.0 root_path handling breaks StaticFiles routes when calling an app with a root_path parameter #2557
Unanswered
wlang42
asked this question in
Potential Issue
Replies: 1 comment
-
This is related to discussion #2495 (because it was caused by PR #2400), but a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It seems that PR #2400 breaks getting files from a mounted StaticFiles
app when started with a
root_path
parameter. It will result in 404HTTP errors, even if the files exist in the specified
StaticFiles
directory.
Looking at the
starlette.staticfiles.StaticFiles.get_path()
method(which in turn uses
starlette._utils.get_route_path()
), which shouldreturn the (file-) path relative the the
StaticFiles.directory
. Here isa test app which overrides the
get_path
method and prints somevariables to see whats going on:
Without
root_path
, everthing works as expected:Ie, the
root_path
(/files
) is removed frompath
(
/files/253912.png -> 253912.png
) and that is found in thefiles
directory.
But when setting the
root_path
(eg/proxy/a
), things go wrong:With
root_path
set to/proxy/a/files
, nothing (except the/
) isstripped from
path
(becauseroot_path
does not match the beginningof
path
) and thus the file path (relative to theStaticFiles
configured directory is not found).
Note that the
root_path
in theStaticFiles
mounted app (and thus inthe
get_path
method) is from the "child_scope" (see PR #2400) andthe original application
root_path
is stored inapp_root_path
.Here is a workaround for StaticFiles to be used with (application)
root_path
:Beta Was this translation helpful? Give feedback.
All reactions