# Hadid Task Manager HTTPS Ingress (Caddy 2)
# Terminates TLS automatically (ACME) and proxies to loopback Hadid API + Next.js UI.

{$HADID_DOMAIN:tasks.example.com} {
	encode zstd gzip

	header {
		Strict-Transport-Security "max-age=31536000; includeSubDomains"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
		Referrer-Policy "strict-origin-when-cross-origin"
		-Server
	}

	request_body {
		max_size 256KB
	}

	# Defense-in-depth edge block for development endpoints (HADID_ENV=prod also returns 403)
	@dev_only path /openapi.json /portal /portal/*
	respond @dev_only 403

	# Hadid Native API + Health Probes
	@api path /api/* /healthz /readyz
	handle @api {
		reverse_proxy 127.0.0.1:8080 {
			header_up X-Forwarded-Proto {scheme}
			header_up X-Real-IP {remote_host}
			transport http {
				dial_timeout 5s
				response_header_timeout 10s
			}
		}
	}

	# Next.js Standalone UI
	handle {
		reverse_proxy 127.0.0.1:3000 {
			header_up X-Forwarded-Proto {scheme}
			header_up X-Real-IP {remote_host}
		}
	}
}
