fix bug
This commit is contained in:
+18
-7
@@ -1,20 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import uvicorn
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
load_dotenv(Path(__file__).resolve().parents[1] / ".env")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _read_port_from_config() -> int:
|
||||
cfg_path = PROJECT_ROOT / "api" / "data" / "config.json"
|
||||
if not cfg_path.exists():
|
||||
return 8008
|
||||
try:
|
||||
data = json.loads(cfg_path.read_text(encoding="utf-8"))
|
||||
value = data.get("api_port", 8008)
|
||||
port = int(value)
|
||||
return port if 1 <= port <= 65535 else 8008
|
||||
except Exception:
|
||||
return 8008
|
||||
|
||||
|
||||
def main() -> None:
|
||||
port = int(os.getenv("DASHBOARD_PORT", "8008"))
|
||||
port = _read_port_from_config()
|
||||
uvicorn.run("api.app.main:app", host="0.0.0.0", port=port, reload=False)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user