#!/usr/bin/env python3
"""Backward-compatible entrypoint. Use `myburn` CLI for new installs."""
import os
from pathlib import Path

os.environ.setdefault("MYBURN_DATA_DIR", str(Path(__file__).parent / "data"))

from myburn.server import app  # noqa: E402

if __name__ == "__main__":
    import sys
    import uvicorn
    host = os.environ.get("MYBURN_HOST", "127.0.0.1")
    port = int(os.environ.get("MYBURN_PORT", "7734"))
    try:
        uvicorn.run(app, host=host, port=port, proxy_headers=True)
    except OSError as e:
        if "address already in use" in str(e).lower() or "10048" in str(e):
            print(f"\n  Port {port} is already in use.")
            print(f"  Try: MYBURN_PORT={port + 1} python3 app.py\n")
            sys.exit(1)
        raise
