From bf65dc8be076d4d8bbb95ed9b77770eb8d746afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gremaud?= Date: Sat, 20 Jun 2026 08:49:21 +0200 Subject: [PATCH] fix: daphne with root-path --- highscore/app/served.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/highscore/app/served.py b/highscore/app/served.py index f0ba827..1816524 100644 --- a/highscore/app/served.py +++ b/highscore/app/served.py @@ -2,18 +2,23 @@ import subprocess import sys from pathlib import Path +from app.config import settings as env + def serve() -> None: """Start the Daphne ASGI server on 0.0.0.0:8080.""" daphne_path = str(Path(sys.path[0]) / "daphne") - subprocess.run( # noqa: S603 - [ - daphne_path, - "-b", - "0.0.0.0", # noqa: S104 - "-p", - "8080", - "app.routing:application", - ], - check=True, - ) + args = [ + daphne_path, + "-b", + "0.0.0.0", # noqa: S104 + "-p", + "8080", + ] + # FORCE_SCRIPT_NAME is a WSGI-only setting; under ASGI Django derives the URL + # script prefix from the scope's root_path. Pass the prefix to Daphne so that + # reverse()/redirects (e.g. the admin post-login redirect) include it. + if env.force_script_name: + args += ["--root-path", env.force_script_name.rstrip("/")] + args.append("app.routing:application") + subprocess.run(args, check=True) # noqa: S603