Files
2026-05-16 19:24:30 -05:00

47 lines
1.2 KiB
Python
Raw Permalink 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
"""生成 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())