fix: daphne with root-path

This commit is contained in:
Loïc Gremaud 2026-06-20 08:49:21 +02:00
parent cbce88f039
commit bf65dc8be0
Signed by: Legrems
GPG Key ID: D4620E6DF3E0121D

View File

@ -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
[
args = [
daphne_path,
"-b",
"0.0.0.0", # noqa: S104
"-p",
"8080",
"app.routing:application",
],
check=True,
)
]
# 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