Skip to content

MARKER

!/usr/bin/env python3

"""Quick fix: add HTML response to COG API root for Safari""" import os

API_PATH = "/var/www/smarthub.my/cog/api.py"

Read current api.py

with open(API_PATH) as f: content = f.read()

Check if already patched

if "text/html" in content: print("Already patched") else: # Replace the root endpoint to serve HTML old_root = '''@app.get("/") def root(): return {"name": "COG", "version": "1.0.0", "network": "CIPHER BuildNet", "status": "live"}'''

new_root = '''from fastapi.responses import HTMLResponse

@app.get("/", response_class=HTMLResponse) def root(): stats = chain.get_stats() balances = chain.get_all_balances() bal_rows = "".join(f"{a}{b:,.0f}" for a, b in sorted(balances.items(), key=lambda x: -x[1])) return f"""<!DOCTYPE html>

COG — Currency of Cognition
CIPHER BuildNet

COG LIVE

Currency of Cognition · Double Ledger · QRNSP-Secured

Supply{stats['total_supply_cog']:,.0f} / {stats['max_supply_cog']:,.0f} COG
Blocks (PKL){stats['pkl_height']}
Transactions{stats['total_transactions']}
Agents{stats['total_agents']}
Contracts{stats['total_contracts']}

Balances

{bal_rows}

API: /cog/stats · /cog/balances · Whitepaper

"""

@app.get("/api") def api_root(): return {"name": "COG", "version": "1.0.0", "network": "CIPHER BuildNet", "status": "live"}'''

if old_root in content:
    content = content.replace(old_root, new_root)
    with open(API_PATH, 'w') as f:
        f.write(content)
    print("✓ Patched api.py with HTML landing page")

    # Restart uvicorn
    import subprocess
    subprocess.run(["pkill", "-f", "uvicorn api:app.*8420"], capture_output=True)
    import time; time.sleep(2)
    subprocess.Popen(
        ["python3", "-m", "uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8420", "--workers", "2"],
        cwd="/var/www/smarthub.my/cog",
        stdout=open("/var/log/cog.log", "w"),
        stderr=subprocess.STDOUT
    )
    time.sleep(3)
    print("✓ Restarted uvicorn")
else:
    print("Root endpoint not found in expected format — manual patch needed")