Skip to content

Commit

Permalink
Static dir 2075 (#2076)
Browse files Browse the repository at this point in the history
* Add support for nested static directories

* Add support for nested static directories

* Bump version 21.3.1
  • Loading branch information
ahopkins committed Mar 21, 2021
1 parent 13630a7 commit 938d2b5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
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"

0 comments on commit 938d2b5

Please sign in to comment.