# Caddyfile for client2server
# Single port (:3843) serves WebSocket and HTTP API; Caddy load-balances
# across server1 and server2 in the Docker network.

{
    # Global options
    # email your@email.com
    admin off
    auto_https off
}

# ========================================
# Unified WebSocket + HTTP load balancer (:3843)
# ========================================
:3843 {
    # Backend servers (Docker network DNS)
    reverse_proxy server1:3843 server2:3843 {
        # Health check each backend
        health_uri /health
        health_interval 10s
        health_timeout 5s
        health_status 2xx

        # Load balancing policy
        lb_policy round_robin

        # WebSocket support (long-lived connections)
        # Caddy auto-detects Upgrade headers, no explicit directive needed
    }

    # Preserve client info
    header_up X-Real-IP {remote}
    header_up X-Forwarded-For {remote}
    header_up X-Forwarded-Proto {scheme}

    # Timeouts for long-lived WebSocket connections
    timeouts {
        read  300s
        write 300s
        idle  300s
    }
}

# ========================================
# Dashboard (port 80/443) - placeholder
# ========================================
:80, :443 {
    respond / "client2server dashboard - not yet implemented" 200
}

# Dashboard placeholder (enable if you have a web UI)
# :80 {
#     reverse_proxy dashboard:3000
# }

# ========================================
# TLS for HTTPS (optional - requires auto_https on)
# ========================================
# tls {
#     # Let's Encrypt (automatic)
# }
