# Caddy: HTTPS (certificates from Let's Encrypt, renewed automatically) in front of the web app and the API.
# DOMAIN and ACME_EMAIL come from the environment (see docker-compose.yml).
{
	email {$ACME_EMAIL}
}

{$DOMAIN} {
	encode zstd gzip

	# API, Meta and Razorpay webhooks, public API: straight to the API (keeps request bodies byte-exact for
	# signature checks, and lets the inbox event stream through without buffering).
	handle /api/* {
		reverse_proxy {$API_UPSTREAM:api:4000} {
			header_up X-Request-Id {http.request.uuid}
			flush_interval -1
			transport http {
				read_timeout 0
			}
		}
	}

	handle {
		reverse_proxy {$WEB_UPSTREAM:web:3000}
	}

	# Uploads are limited by the API itself (16 MB media, 5 MB imports); this is an outer bound.
	request_body {
		max_size 110MB
	}

	log {
		output stdout
		format json
	}
}
