feat(backend): bind serve to 127.0.0.1:8000, honor CYCLONE_PORT/CYCLONE_RELOAD
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
"""Entry point for ``python -m cyclone``.
|
||||
|
||||
* ``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
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == "serve":
|
||||
# Strip the "serve" subcommand so uvicorn doesn't try to interpret
|
||||
# any additional flags we might forward in the future.
|
||||
sys.argv = [sys.argv[0], "cyclone.api:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
port = os.environ.get("CYCLONE_PORT", "8000")
|
||||
reload = os.environ.get("CYCLONE_RELOAD", "0") == "1"
|
||||
sys.argv = [
|
||||
sys.argv[0],
|
||||
"cyclone.api:app",
|
||||
"--host", "127.0.0.1",
|
||||
"--port", port,
|
||||
]
|
||||
if reload:
|
||||
sys.argv.append("--reload")
|
||||
import uvicorn
|
||||
|
||||
uvicorn.main()
|
||||
|
||||
Reference in New Issue
Block a user