Static dir 2075 (#2076)

* Add support for nested static directories

* Add support for nested static directories

* Bump version 21.3.1
This commit is contained in:
Adam Hopkins 2021-03-21 15:03:54 +02:00 committed by GitHub
parent 13630a79ad
commit 938d2b5923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 2 deletions

BIN
examples/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,2 @@
User-agent: *
Disallow: /

View File

@ -0,0 +1,6 @@
from sanic import Sanic
app = Sanic(__name__)
app.static("/", "./static")

View File

@ -1 +1 @@
__version__ = "21.3.0"
__version__ = "21.3.1"

View File

@ -776,7 +776,7 @@ class RouteMixin:
# 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_"):

View File

@ -0,0 +1 @@
foo

View File

@ -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"