File size: 1,363 Bytes
a959408
 
b3f739e
a959408
 
 
 
 
 
 
 
 
 
 
b3f739e
a959408
 
 
 
b3f739e
a959408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# main.py — ASGI entrypoint for BubbleGuard Web (HF-ready, with GDrive fetch)

import os, sys, traceback

def _truthy(val: str) -> bool:
    return str(val).strip().lower() in {"1", "true", "yes", "on"}

def main() -> None:
    host = os.getenv("HOST", "0.0.0.0")
    port = int(os.getenv("PORT", "8000"))
    debug = _truthy(os.getenv("DEBUG", "0"))

    print(f"[BubbleGuard] Starting server on {host}:{port}")
    folder_id = os.getenv("GDRIVE_FOLDER_ID", "").strip()
    print(f"[BubbleGuard] GDRIVE_FOLDER_ID: {folder_id or '(not set!)'}")

    try:
        from download_assets import ensure_all_assets
        ensure_all_assets()
    except Exception:
        print("[BubbleGuard] ERROR while preparing assets:", file=sys.stderr)
        traceback.print_exc()
        raise SystemExit(1)

    try:
        import uvicorn
        uvicorn.run(
            "app_server:app",
            host=host,
            port=port,
            reload=False,
            workers=1,
            log_level="debug" if debug else "info",
            proxy_headers=True,
            forwarded_allow_ips="*",
            timeout_keep_alive=10,
            access_log=True,
        )
    except Exception:
        print("[BubbleGuard] Uvicorn failed to start:", file=sys.stderr)
        traceback.print_exc()
        raise SystemExit(1)

if __name__ == "__main__":
    main()