From e91d185996d810bd9dfbc8d48b37b4b724e395cb Mon Sep 17 00:00:00 2001 From: kunthawat Date: Sat, 3 Oct 2026 15:19:09 +0700 Subject: [PATCH] fix: module-level app loads config.yaml (uvicorn app.main:app); bind 0.0.0.0 for LAN/device reachability --- README.md | 1 + app/main.py | 18 +++++++++++------- config.yaml | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dbffe1b..4dc7e6c 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ cd hermes-xiaozhi-bridge python3 -m venv .venv && .venv/bin/pip install -r requirements.txt .venv/bin/python -m app.main # (loads config.yaml from the repo root; override with BRIDGE_CONFIG=/path) +# equivalent: .venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8766 .venv/bin/python -m pytest -q ``` diff --git a/app/main.py b/app/main.py index 030455b..175b942 100644 --- a/app/main.py +++ b/app/main.py @@ -38,13 +38,6 @@ def make_app(cfg: Config | None = None) -> FastAPI: return app -def main() -> None: - import uvicorn - - cfg = _load_config() - uvicorn.run(make_app(cfg), host=cfg.host, port=cfg.port) - - def _load_config() -> Config: """Load config.yaml from the repo root; fall back to all-mock defaults.""" import os @@ -58,5 +51,16 @@ def _load_config() -> Config: return Config() +# Module-level app so `uvicorn app.main:app` loads config.yaml (REQ: real +# token in production). `main()` is the equivalent entrypoint. +app = make_app(_load_config()) + + +def main() -> None: + import uvicorn + + uvicorn.run(app, host=app.state.cfg.host, port=app.state.cfg.port) + + if __name__ == "__main__": main() diff --git a/config.yaml b/config.yaml index a2abc8e..fe8d028 100644 --- a/config.yaml +++ b/config.yaml @@ -6,7 +6,7 @@ # Protocol values marked FIRMWARE are PoC assumptions — verify against the # real Xiaozhi firmware before locking (CON-004). -host: 127.0.0.1 +host: 0.0.0.0 # LAN reachable (device on 192.168.1.x) port: 8766 ws_path: /ws/xiaozhi