# Caddy in front of Reviir (docs/auto-update-plan.md §9). Caddy terminates TLS and, during an update or any
# restart, keeps retrying the upstream instead of answering 502: clients see a short pause, not an error.
#
# Install: copy to /etc/caddy/Caddyfile, replace the host name, then `systemctl reload caddy`.
# Reviir: set AppBaseUrl to https://reviir.example.com. Caddy on the same host is trusted for
# X-Forwarded-For / -Proto automatically; on another host add it to ForwardedHeaders:KnownProxies.

reviir.example.com {
	encode zstd gzip

	reverse_proxy 127.0.0.1:5000 {
		# Hold requests while Reviir restarts (an update pauses it for a few seconds).
		lb_try_duration 30s
		lb_try_interval 250ms
		# A single upstream must never be marked down: keep trying it.
		fail_duration 0

		# Long-lived connections: Blazor circuits, edge relays (/edge/…) and live video (/stream-ws/…).
		stream_timeout 24h
		stream_close_delay 5s
	}

	# Images and the Pulse PWA can be large; ingest bodies are limited by Reviir itself.
	request_body {
		max_size 32MB
	}
}

# MQTT (1883), SMTP (25) and SIA (2000/2001) are plain TCP and connect to Reviir directly, not through Caddy.
