# HTTPS in front of VitalRix. VITALRIX_TLS chooses the certificate:
#   internal                              Caddy's own certificate authority (trust it once: ./vitalrix ca-cert)
#   you@company.com                       Let's Encrypt (the hosts must be reachable from the internet)
#   /certs/fullchain.pem /certs/privkey.pem   your company's certificate (a wildcard for *.<domain>), in ./certs
{
	# the proxy listens on the public ports themselves (HTTP_PORT, HTTPS_PORT in .env)
	http_port {$HTTP_PORT:80}
	https_port {$HTTPS_PORT:443}
	# Caddy's own http -> https redirect leaves out a port other than 443; the one at the end of this file keeps it
	auto_https disable_redirects
}

(vitalrix) {
	tls {$VITALRIX_TLS}
	encode zstd gzip
	header -Server
}

monitor.{$VITALRIX_DOMAIN} {
	import vitalrix
	reverse_proxy vitalrix:3002
}

api.{$VITALRIX_DOMAIN} {
	import vitalrix
	reverse_proxy vitalrix:4000 {
		flush_interval -1
	}
}

docs.{$VITALRIX_DOMAIN} {
	import vitalrix
	reverse_proxy vitalrix:3003
}

# Extra sites of your own: put *.caddy files in sites/.
import sites/*.caddy

# Plain HTTP: to HTTPS on the public port (certificate challenges on this port are still answered first)
http:// {
	redir https://{host}:{$HTTPS_PORT:443}{uri} permanent
}
