# Caddyfile for the self-host stack: ONE domain, two upstreams. # # `{$COHORLY_DOMAIN}` gets automatic HTTPS: a public name gets a Let's Encrypt # certificate, `localhost` gets Caddy's internal CA (use `curl -k`). # # Plain HTTP (port 80) serves nothing: Caddy answers every path, ingestion # included, with a 308 to the same URL over HTTPS. Unlike the hosted API # (root Caddyfile), a self-host instance has no SDKs in the field that were # set up with an http:// host, so it keeps no plain HTTP ingestion # (deploy/README.md, "Plain HTTP"). # # This Caddy is the only edge. Without `trusted_proxies`, Caddy discards any # X-Forwarded-For sent by the client and sets it to the address it saw, which # is what the API's rate limits (COHORLY_TRUSTED_PROXY_HOPS=1) rely on. # # API paths. /admin/* (the superadmin # backoffice API), /contact (the public contact form) and /status* are # deliberately not exposed. Everything else # is the dashboard. Paths that exist on both sides are matched exactly: # /mcp (protocol) vs the dashboard page /mcp/approve, /replay (ingest) vs the # dashboard page /replays, /signup/validate-invite vs the page /signup. {$COHORLY_DOMAIN} { # Replaces the Strict-Transport-Security the API and the dashboard send # themselves: max-age and includeSubDomains, and never preload, which the # hosted dashboard sends for cohorly.com only (VEL-2089). Never sent for # localhost, where it would pin https on every localhost port of the # browser. @hsts_local host localhost *.localhost @hsts_public not host localhost *.localhost header @hsts_local -Strict-Transport-Security header @hsts_public >Strict-Transport-Security "max-age=63072000; includeSubDomains" @api { path /track /engage /alias /replay /health /mcp /mcp/ path /flags/evaluate /flags/local-evaluation /signup/validate-invite path /api/* /.well-known/* } handle @api { # Docker DNS is resolved per connection, plus a short retry window, so # an API restart does not fail requests that arrive during it. reverse_proxy server:4000 { lb_try_duration 10s lb_try_interval 250ms # No buffering: /api/ai answers with server-sent events. flush_interval -1 # Idle upstream connections close after 3s, before the server's # 5s keep-alive timeout and the 4s it waits on shutdown before # closing idle connections, so the server never closes one Caddy # is about to reuse. transport http { keepalive 3s } } } handle { reverse_proxy dashboard:3000 { flush_interval -1 } } }