"""
应用启动入口：读取 Config 并启动 Uvicorn。
开发与生产均使用该单一角色入口，由外层脚本/编排并行管理。
"""

from pathlib import Path
import uvicorn

from jingrow.config import Config


def main() -> None:
    env = str(getattr(Config, "environment", "development")).lower()
    is_production = env == "production"

    host = getattr(Config, "backend_host", "0.0.0.0")
    port = int(getattr(Config, "backend_port", 9001))
    reload_enabled = (not is_production) and bool(getattr(Config, "backend_reload", True))

    apps_dir = Path(__file__).resolve().parents[2]
    reload_dirs = [str(apps_dir)] if reload_enabled else None

    uvicorn.run(
        "jingrow.main:app",
        host=host,
        port=port,
        reload=reload_enabled,
        reload_dirs=reload_dirs,
    )


if __name__ == "__main__":
    main()


