# Copyright (c) 2026 Gravita Technology
# SPDX-License-Identifier: AGPL-3.0-only
# Caddy reverse proxy and public media folder configuration (T001, T003, S-50, NFR-04, NFR-05, FR-ANL-06).

{$PUBLIC_DOMAIN} {
  encode zstd gzip

  header {
    Strict-Transport-Security "max-age=31536000; includeSubDomains"
    X-Content-Type-Options "nosniff"
    Referrer-Policy "strict-origin-when-cross-origin"
  }

  # Public media folder served directly from the Docker volume with directory listing OFF (S-50, T003, NFR-05).
  # Paths carry random unguessable directories written at upload/render time.
  handle_path /media/* {
    root * /srv/blessor-media
    header Cache-Control "public, max-age=31536000, immutable"
    file_server
  }

  # Privacy-preserving access log: drop client IP and User-Agent so short links (/l/*) never log personal identifiers (FR-ANL-06, TC-106).
  log {
    output stdout
    format filter {
      wrap json
      fields {
        request>remote_ip delete
        request>client_ip delete
        request>headers>User-Agent delete
        request>headers>Cookie delete
        request>headers>Authorization delete
      }
    }
  }

  reverse_proxy {$INTEGRATION_UPSTREAM}
}
