# The site block for one slug under /srv/www. Caddy issues and renews the
# certificate itself, so this is the whole configuration for the host.
#
# /srv/www/pplus is a symlink to the current release (scripts/deploy.sh);
# Caddy follows symlinks by default. Routing lives in the URL hash, so every
# path is the one page and no rewrite is needed beyond serving index.html.
pplus.scient.ing {
    root * /srv/www/pplus
    encode zstd gzip
    file_server

    # The modules and the stylesheet change on every deploy: revalidate rather
    # than serve a stale module against a new index.html.
    @code path *.js *.css
    header @code Cache-Control "no-cache"
    header /VERSION Cache-Control "no-store"

    # Course pages embed views in iframes, so no X-Frame-Options here; allow
    # framing from the course origins, and from a local `quarto preview` of them.
    header Content-Security-Policy "frame-ancestors 'self' https://scient.ing https://*.scient.ing http://localhost:* http://127.0.0.1:*"

    # A deleted path falls through to the app rather than a bare 404.
    handle_errors {
        @notfound expression {http.error.status_code} == 404
        rewrite @notfound /index.html
        file_server
    }
}
