nomadro/apps/api/run.py
Eric 017008dd7c Harden weapp/API P0 paths: VIP auth, ebook login, WAL limits, game stub.
Drop Three from weapp game, mount VIP library on unified API, and auto-enable local debug without manual .env.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 19:06:50 +08:00

37 lines
953 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""统一后端启动:uvicorn app.main:app"""
from __future__ import annotations
import os
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
SERVICES = ROOT / "services"
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(SERVICES))
_LOCAL_ENV = """# 本地开发自动生成 — 勿提交
DEBUG=true
WX_ALLOW_DEVTOOLS_LOGIN=true
"""
def _ensure_local_env() -> None:
"""缺 .env 时自动写入本地调试开关,避免手动配。"""
if os.getenv("NOMADRO_ENV", "").lower() in {"prod", "production"}:
return
env_path = ROOT / ".env"
if env_path.exists():
return
env_path.write_text(_LOCAL_ENV, encoding="utf-8")
if __name__ == "__main__":
import uvicorn
_ensure_local_env()
host = os.getenv("HOST", "127.0.0.1")
port = int(os.getenv("PORT", "8080"))
uvicorn.run("app.main:app", host=host, port=port, reload=os.getenv("RELOAD") == "1")