# Production. The apex serves only the registry and otherwise redirects, so # www is the one origin cookies and CORS assume. # DNS-01 because no ACME server can reach us behind the tunnel. Public # resolvers because DOMAIN is a Docker alias for this container, which would # fail the zone lookup ("expected 1 zone, got 0"). (prod_tls) { tls { dns cloudflare {env.CLOUDFLARE_DNS_API_TOKEN} resolvers 1.1.1.1 1.0.0.1 } } # Explicit so http://apex is one hop to www, not two. http://{$DOMAIN}, http://www.{$DOMAIN} { import logging header -Server redir https://www.{$DOMAIN}{uri} 301 } {$DOMAIN} { import prod_tls import common header Strict-Transport-Security "max-age=63072000; includeSubDomains" route { # Docker clients expect /v2/ (and Gitea's token endpoint) at the apex root # and don't all follow redirects on blob uploads. No body limit: layers # are large and stream through. handle /v2/* { reverse_proxy {$GITEA_HOST}:{$GITEA_PORT} { import proxy } } redir https://www.{$DOMAIN}{uri} 301 } } www.{$DOMAIN} { import prod_tls import common import security_headers # ---- Static asset caching ---- # `file` so a 404 for a not-yet-deployed hash is never cached as immutable. @hashed { path /assets/* file { root /srv/www } } header @hashed Cache-Control "public, max-age=31536000, immutable" @fonts { path /fonts/* file { root /srv/www } } header @fonts Cache-Control "public, max-age=2592000" @week { path /img/* /sound/* file { root /srv/www } } header @week Cache-Control "public, max-age=604800" # A hot-linked web stamp; public and uncredentialed, so `*` is safe. header /img/stamps/mine.gif Access-Control-Allow-Origin "*" route { import ../routes.caddy # 404 rather than index.html, so a stale asset hash isn't served HTML. @static path /assets/* /fonts/* /img/* /sound/* handle @static { root * /srv/www file_server } # SPA fallback so deep links work on refresh. handle { root * /srv/www try_files {path} {path}/ /index.html file_server } } } # ---- Partner Radar (radar.DOMAIN) ---- # The adamf/cto stack's own Caddy. A subdomain because the app assumes it owns # `/`. No gate (it has its own login) and no security_headers (it sends its # own, and www's would block the app). (radar_proxy) { reverse_proxy {$RADAR_UPSTREAM} { import proxy # Fail fast when the stack is down. transport http { dial_timeout 3s } } } radar.{$DOMAIN} { import prod_tls import common header Strict-Transport-Security "max-age=63072000; includeSubDomains" route { import limit radar 30 1s request_body { max_size 10MB } vars radar_upstream yes handle /api/auth/login { route { import limit radar_login 5 1m import radar_proxy } } handle { import radar_proxy } } }