{
	servers {
		metrics
	}
	admin 0.0.0.0:2019
}

(security_headers) {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
		Referrer-Policy "strict-origin-when-cross-origin"
		Permissions-Policy "camera=(), microphone=(), geolocation=()"
		Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' blob:; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://*.tile.openstreetmap.org; connect-src 'self' wss: https://*.sentry.io https://*.ingest.de.sentry.io; font-src 'self';"
	}
}

(block_scanners) {
	@scanners path /.env* /.git* /wp-* /wp-admin* /admin* /config.* /backup* /.aws* /.docker* /composer* /vendor* *.php *.asp
	respond @scanners 403
}

{$DOMAIN:trails.cool} {
	import security_headers
	import block_scanners
	log {
		output stdout
		format json
	}
	reverse_proxy journal:3000 {
		# During an `apps` deploy the journal container is briefly down
		# (~10–30s) while compose swaps containers. Without these,
		# Caddy returns 502 immediately and the `caddy-502-rate` alert
		# trips on every deploy. With them, Caddy holds and retries
		# against the upstream for up to 30s — restart becomes
		# invisible to clients. A real outage longer than 30s still
		# 502s and correctly trips the alert.
		lb_try_duration 30s
		lb_try_interval 250ms
	}
}

www.{$DOMAIN:trails.cool} {
	redir https://{$DOMAIN:trails.cool}{uri} permanent
}

grafana.internal.{$DOMAIN:trails.cool} {
	reverse_proxy grafana:3000
}

planner.{$DOMAIN:trails.cool} {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
		Referrer-Policy "strict-origin-when-cross-origin"
		Permissions-Policy "camera=(), microphone=(), geolocation=()"
		Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' blob:; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://*.tile.openstreetmap.org; connect-src 'self' wss: https://{$DOMAIN:trails.cool} https://*.sentry.io https://*.ingest.de.sentry.io; font-src 'self';"
	}
	import block_scanners
	log {
		output stdout
		format json
	}
	reverse_proxy planner:3001 {
		# Same rationale as the journal block — see the comment there.
		lb_try_duration 30s
		lb_try_interval 250ms
	}
}
