# ---------------------------------------------------------------------------
# Caddyfile
#
# Install at /etc/caddy/Caddyfile (or merge with your existing one), edit the
# placeholders below, then: sudo systemctl reload caddy
#
# Caddy auto-provisions Let's Encrypt certs for every site block.  DNS for
# both subdomains must point at this Caddy host's public IP first.
#
# Placeholders to replace:
#   yourdomain.com    -> your real domain
#   192.168.1.50      -> Frigate host LAN IP
#   192.168.1.60      -> Pi Zero W LAN IP (when you set up the doorbell)
# ---------------------------------------------------------------------------

# ---------- Frigate authenticated UI ----------
cam.yourdomain.com {
    encode zstd gzip

    reverse_proxy 192.168.1.50:8971 {
        transport http {
            read_timeout  60s
            write_timeout 60s
        }
    }
}

# ---------- Doorbell PTT page (Pi Zero W) ----------
# Comment out this whole block until the Pi is deployed.
doorbell.yourdomain.com {
    encode zstd gzip

    # Same-origin proxy to Frigate so the browser's WebRTC fetch works
    # without CORS issues. /frigate/* is stripped before forwarding.
    handle_path /frigate/* {
        reverse_proxy 192.168.1.50:8971 {
            transport http {
                read_timeout  60s
                write_timeout 60s
            }
        }
    }

    # Everything else (HTML page + /audio WebSocket) goes to the Pi.
    handle {
        reverse_proxy 192.168.1.60:5555
    }
}
