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
RouteExists
thrown when registering a directory and a missing file to the same route.
#2132
Comments
This is not really a bug, and is an intended outcome. Sanic is checking to see if a file like that exists. If not, it thinks you are trying to serve from a directory. Just by looking at the path, there is no way to determine if you intend to serve a file or a directory. I think this is the correct behavior. If anything, perhaps what you really want is an explicit method to control this: app.static('/', './resources/web', as="dir")
app.static('/', './resources/web/example.html', as="file") With an explicit kwarg, we would not need to run A bit of behind the scenes info... Let's look at what these two are doing: app.static("/", "./resources/web")
# Sanic checks this, sees that it is not a file and then converts to:
# "/<__file_uri__:path>"
# meaning that it will look for anything that matches using the `path` param type
app.static('/', './resources/web/example.html')
# If this is indeed a file, Sanic knows that you meant for an explicit path "/"
# There is no ambiguity, and the path does not need to be altered
# If the file does not exist, then like the first example, it tries to convert it to a `path` type
# But, since you already have a path expansion on that base path, there is now ambiguity
# and Sanic raises RouteExists |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
Describe the bug
When registering a route to a file and a directory, if the file doesn't exist a
sanic_routing.exceptions.RouteExists
error is raised. This may be misleading and unintended.Code snippet
example.html
does not exist in this example. The directory./resources/web
does.Expected behavior
Currently, if a non existent file is registered to a route, no error is thrown on startup and any attempt to retrieve registered resource raises a
FileNotFoundError: [Errno 2] No such file or directory
and a404 Not Found
error is displayed in the browser. Instead of this happening, as mentioned before asanic_routing.exceptions.RouteExists
is raised on startup which may be misleading and unintended.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: