fix: module-level app loads config.yaml (uvicorn app.main:app); bind 0.0.0.0 for LAN/device reachability

This commit is contained in:
2026-10-03 15:19:09 +07:00
parent b00312cbe5
commit e91d185996
3 changed files with 13 additions and 8 deletions

View File

@@ -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
```

View File

@@ -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()

View File

@@ -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