# Caddy for the compose file's `caddy` profile: automatic TLS for both hosts (the DNS of each must # point at this machine, ports 80 and 443 open). Studio and the API at CLOUDHAL_BASE_URL, proxied # with X-Forwarded-Proto/Host/For (set CLOUDHAL_BEHIND_PROXY=1); the public site at # CLOUDHAL_SITE_URL, from /data/dist: the built site as `site-build` publishes it (a real folder # with the 0.6.3 image; a symlink to /data/site/current, swapped atomically, from 0.6.4 on). Before # the first publish that build is the not-published status page, answered with 503 (0.7.2 on). {$CLOUDHAL_BASE_URL} { reverse_proxy cloudhal:8787 } {$CLOUDHAL_SITE_URL} { root * /srv/cloudhal/dist encode zstd gzip # The build's `_headers` file (the security headers of the Cloudflare deployment) is for hosts # that read it; Caddy does not. Media files, Astro's assets and the renderer's scripts are named # by content hash and never change under a path: immutable, but only when the file exists, so a # miss is never cached. Add the security headers from `_headers` here if you want them. @immutable { path /media/* /_astro/* /_cloudhal/* file } header @immutable Cache-Control "public, max-age=31536000, immutable" # Before the first publish `site-build` (`cloudhal build --published`, RFC-0043 ยง1.10) writes # the not-published status page instead of the site, with a `.cloudhal-status` marker. While # the marker exists every path but robots.txt (which must not be a 503, and disallows all) is # that page with 503, Retry-After and no-store: crawlers come back later and nothing is cached # or indexed. These are the headers the Cloudflare deployment sends with the same page. @status { file /.cloudhal-status not path /robots.txt } handle @status { header { Cache-Control "no-store" Retry-After "3600" X-Robots-Tag "noindex" X-Cloudhal-State "not-published" X-Content-Type-Options "nosniff" Referrer-Policy "no-referrer" Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'" } rewrite * /index.html file_server { status 503 } } # A page opened before the last build may still ask for that build's hashed assets: they come # from /data/site/previous, the build before the current one (0.6.4 and later; immutable too). @previous { path /_astro/* /_cloudhal/* /media/* not file file { root /srv/cloudhal/site/previous } } handle @previous { root * /srv/cloudhal/site/previous header Cache-Control "public, max-age=31536000, immutable" file_server } handle { try_files {path} {path}/ {path}.html file_server } handle_errors { # /404.html exists only when the site has a page at /404 (the starter ships none); until # then a miss is Caddy's plain 404. @notfound expression {err.status_code} == 404 rewrite @notfound /404.html file_server } }