import reflex as rx
from reflex.plugins import SitemapPlugin
import os

# --- AUTOMATISCHER VITE-PATCH FÜR LINUX ---
# Sucht die von Reflex generierte Vite-Konfiguration
VITE_CONFIG_PATH = os.path.join(os.path.dirname(__file__), ".web", "vite.config.js")

if os.path.exists(VITE_CONFIG_PATH):
    try:
        with open(VITE_CONFIG_PATH, "r", encoding="utf-8") as f:
            content = f.read()
        
        # Wenn der Host noch nicht erlaubt ist, patchen wir das 'server'-Objekt
        if "allowedHosts" not in content:
            # Wir fügen allowedHosts direkt in die Server-Konfiguration von Vite ein
            patched_content = content.replace(
                "server: {",
                "server: {\n    allowedHosts: ['man-dan-05', 'localhost', '127.0.0.1'],"
            )
            with open(VITE_CONFIG_PATH, "w", encoding="utf-8") as f:
                f.write(patched_content)
            print("[INFO] Vite-Sicherheitsblockade erfolgreich im Code gelöst!")
    except Exception as e:
        print(f"[WARNUNG] Patch fehlgeschlagen: {str(e)}")


config = rx.Config(
    app_name="app",
    frontend_port=8080,
    backend_port=8081,
    api_url="http://man-dan-05:8081",
    
    #    ssl_cert="certs/man-dan-05.crt",
    #ssl_key="certs/man-dan-05.key",
    
    disable_plugins=[SitemapPlugin],
)
