feat(backend): bind serve to 127.0.0.1:8000, honor CYCLONE_PORT/CYCLONE_RELOAD

This commit is contained in:
Tyler
2026-06-19 19:30:55 -06:00
parent 74a673a360
commit 07ceeaf4cd
+17 -4
View File
@@ -1,19 +1,32 @@
"""Entry point for ``python -m cyclone``. """Entry point for ``python -m cyclone``.
* ``python -m cyclone`` (no args) — Click CLI (``cli.main``) * ``python -m cyclone`` (no args) — Click CLI (``cli.main``)
* ``python -m cyclone serve`` — start the FastAPI app on port 8000 * ``python -m cyclone serve`` — start the FastAPI app on 127.0.0.1:8000
Honors the env vars:
* ``CYCLONE_PORT`` (default ``8000``)
* ``CYCLONE_RELOAD`` (default ``0``; set to ``1`` to enable uvicorn reload)
""" """
from __future__ import annotations from __future__ import annotations
import os
import sys import sys
def main() -> None: def main() -> None:
if len(sys.argv) >= 2 and sys.argv[1] == "serve": if len(sys.argv) >= 2 and sys.argv[1] == "serve":
# Strip the "serve" subcommand so uvicorn doesn't try to interpret port = os.environ.get("CYCLONE_PORT", "8000")
# any additional flags we might forward in the future. reload = os.environ.get("CYCLONE_RELOAD", "0") == "1"
sys.argv = [sys.argv[0], "cyclone.api:app", "--host", "0.0.0.0", "--port", "8000"] sys.argv = [
sys.argv[0],
"cyclone.api:app",
"--host", "127.0.0.1",
"--port", port,
]
if reload:
sys.argv.append("--reload")
import uvicorn import uvicorn
uvicorn.main() uvicorn.main()