Skip to content
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

Static dir 2075 #2076

Merged
merged 3 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/static/favicon.ico
Binary file not shown.
Binary file added examples/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /
6 changes: 6 additions & 0 deletions examples/static_assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sanic import Sanic


app = Sanic(__name__)

app.static("/", "./static")
2 changes: 1 addition & 1 deletion sanic/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "21.3.0"
__version__ = "21.3.1"
2 changes: 1 addition & 1 deletion sanic/mixins/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def _register_static(
# If we're not trying to match a file directly,
# serve from the folder
if not path.isfile(file_or_directory):
uri += "/<__file_uri__>"
uri += "/<__file_uri__:path>"

# special prefix for static files
# if not static.name.startswith("_static_"):
Expand Down
1 change: 1 addition & 0 deletions tests/static/nested/dir/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
9 changes: 9 additions & 0 deletions tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,12 @@ def test_static_name(app, static_file_directory, static_name, file_name):
request, response = app.test_client.get(f"/static/{file_name}")

assert response.status == 200


def test_nested_dir(app, static_file_directory):
app.static("/static", static_file_directory)

request, response = app.test_client.get("/static/nested/dir/foo.txt")

assert response.status == 200
assert response.text == "foo\n"