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