This commit is contained in:
eric
2026-03-28 13:27:53 -05:00
parent d34ecab19c
commit 8053c4cb6d
48 changed files with 3527 additions and 1433 deletions

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""生成 Caddy 配置HTTP :80 → 本机 FastAPI+静态PORT默认 8001"""
from __future__ import annotations
import json
import sys
from pathlib import Path
def main() -> int:
alias = "live"
port = "8001"
out = Path("/opt/live/generated/Caddyfile")
cfg = Path("/opt/live/config/system.json")
if cfg.is_file():
data = json.loads(cfg.read_text(encoding="utf-8"))
ident = data.get("identity") or {}
web = data.get("web_console") or {}
alias = str(ident.get("hostname_alias") or alias)
if web.get("api_port") is not None:
port = str(web["api_port"])
if len(sys.argv) >= 2:
alias = sys.argv[1]
if len(sys.argv) >= 3:
port = sys.argv[2]
if len(sys.argv) >= 4:
out = Path(sys.argv[3])
host = f"{alias}.local"
body = f"""# Generated by live-platform/tools/render_caddyfile.py - do not hand-edit
# http://{host}/ and http://<LAN-IP>/ -> 127.0.0.1:{port}
{host}:80, :80 {{
\treverse_proxy 127.0.0.1:{port}
}}
"""
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(body, encoding="utf-8")
print(str(out))
return 0
if __name__ == "__main__":
raise SystemExit(main())