From 29c5e218326fa415fccb93cd3e8c43daa12f98e5 Mon Sep 17 00:00:00 2001 From: Pedro Gandarinho Date: Wed, 26 Jun 2024 14:33:30 +0100 Subject: [PATCH] Adding support for catch-all URLs --- docs/ENV.md | 2 ++ piku.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/ENV.md b/docs/ENV.md index 8639627..c1f2ea6 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -71,6 +71,8 @@ Also, keep in mind that using `nginx` caching with a `static` website worker wil * `NGINX_INCLUDE_FILE`: a file in the app's dir to include in nginx config `server` section - useful for including custom `nginx` directives. * `NGINX_ALLOW_GIT_FOLDERS`: (boolean) allow access to `.git` folders (default: false, blocked) +* `NGINX_CATCH_ALL` (string, defaults to ""): specifies a filename to serve to all requests regardless of path (useful when using client-side routing) + ## Acme Settings diff --git a/piku.py b/piku.py index 142e906..53c9f1e 100755 --- a/piku.py +++ b/piku.py @@ -171,7 +171,7 @@ PIKU_INTERNAL_NGINX_STATIC_MAPPING = """ directio 8m; aio threads; alias $static_path; - try_files $uri $uri.html $uri/ =404; + try_files $uri $uri.html $uri/ $catch_all =404; } """ @@ -934,6 +934,8 @@ def spawn_app(app, deltas={}): static_paths = ("/" if stripped[0:1] == ":" else "/:") + (stripped if stripped else ".") + "/" + ("," if static_paths else "") + static_paths if len(static_paths): try: + # pylint: disable=unused-variable + catch_all = env.get('NGINX_CATCH_ALL', '') items = static_paths.split(',') for item in items: static_url, static_path = item.split(':')