diff --git a/examples/static/favicon.ico b/examples/static/favicon.ico new file mode 100644 index 00000000..3b39e5d7 Binary files /dev/null and b/examples/static/favicon.ico differ diff --git a/examples/static/images/logo.png b/examples/static/images/logo.png new file mode 100644 index 00000000..f56cc941 Binary files /dev/null and b/examples/static/images/logo.png differ diff --git a/examples/static/robots.txt b/examples/static/robots.txt new file mode 100644 index 00000000..1f53798b --- /dev/null +++ b/examples/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/examples/static_assets.py b/examples/static_assets.py new file mode 100644 index 00000000..23f324ef --- /dev/null +++ b/examples/static_assets.py @@ -0,0 +1,6 @@ +from sanic import Sanic + + +app = Sanic(__name__) + +app.static("/", "./static") diff --git a/sanic/__version__.py b/sanic/__version__.py index 7cd09f62..66db1623 100644 --- a/sanic/__version__.py +++ b/sanic/__version__.py @@ -1 +1 @@ -__version__ = "21.3.0" +__version__ = "21.3.1" diff --git a/sanic/mixins/routes.py b/sanic/mixins/routes.py index f181e83b..f57bf230 100644 --- a/sanic/mixins/routes.py +++ b/sanic/mixins/routes.py @@ -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_"): diff --git a/tests/static/nested/dir/foo.txt b/tests/static/nested/dir/foo.txt new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/tests/static/nested/dir/foo.txt @@ -0,0 +1 @@ +foo diff --git a/tests/test_static.py b/tests/test_static.py index 24b5c568..532adb80 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -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"