Files
adamfandClaude Opus 5.5 4530cb8dc4
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s
Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 20:49:03 +00:00

130 lines
2.8 KiB
Plaintext

# 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
}
}
}