# /etc/caddy/Caddyfile on the VPS.
# The domain's A/AAAA record must already point at this VPS — Caddy provisions a
# Let's Encrypt cert on first request and auto-renews. Nothing else to do for TLS
# (just make sure ports 80 and 443 are open).
#
# Layout on this domain:
#   /                -> static portfolio site (served straight from disk)
#   /thermograph/*   -> reverse-proxied to the Thermograph uvicorn (loopback)
#
# Thermograph must run with THERMOGRAPH_BASE=/thermograph (see /etc/thermograph.env)
# so the app serves itself under that prefix. The app no longer claims "/", so the
# root is free for the portfolio.

emigriffith.dev {
	encode zstd gzip

	# Thermograph — the app serves all pages, assets, and API under /thermograph.
	# Match both the bare prefix and everything beneath it; the app redirects the
	# bare /thermograph to /thermograph/.
	handle /thermograph /thermograph/* {
		reverse_proxy 127.0.0.1:8137
	}

	# Portfolio at the root. Point `root` at the built static site (for the Astro
	# portfolio that's its `dist/` output). file_server serves index.html for
	# directories and returns a real 404 for missing paths.
	handle {
		root * /var/www/emigriffith
		file_server
	}

	log {
		output file /var/log/caddy/emigriffith.log
	}
}

# Optional: redirect www -> apex. Add a www CNAME/A record first, then uncomment.
# www.emigriffith.dev {
# 	redir https://emigriffith.dev{uri} permanent
# }
