# Serveur statique d'Ustagammon. CapRover fournit le HTTPS devant ; ici on
# écoute en HTTP sur le port 80 du conteneur.
{
	admin off
	auto_https off
}

:80 {
	root * /srv
	# Types compressés : ceux de Caddy par défaut, plus les données du moteur
	# (application/octet-stream, 8,7 Mo, 7,2 Mo compressés).
	encode {
		zstd
		gzip
		match {
			header Content-Type text/*
			header Content-Type application/json*
			header Content-Type application/javascript*
			header Content-Type application/wasm*
			header Content-Type application/octet-stream*
			header Content-Type application/manifest+json*
			header Content-Type image/svg+xml*
		}
	}

	# Les noms de fichiers ne changent pas d'une version à l'autre : le
	# navigateur revalide chaque fichier (ETag) au lieu de garder une copie
	# périmée.
	header Cache-Control "no-cache"
	header X-Content-Type-Options "nosniff"
	header Referrer-Policy "no-referrer"

	# Politique de sécurité du contenu : tout vient du site lui-même, sans
	# script ni style en ligne. 'wasm-unsafe-eval' autorise la compilation du
	# moteur WebAssembly (et rien d'autre : ni eval ni new Function). L'en-tête
	# s'applique aussi au Web Worker du moteur et au service worker.
	header Content-Security-Policy "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self'; img-src 'self'; connect-src 'self'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"

	# Données du moteur (Emscripten) : extension inconnue de Caddy, qui
	# devinerait text/xml d'après le début du fichier.
	@engine_data path *.data
	header @engine_data Content-Type "application/octet-stream"

	# Textes de l'aide (copies de docs/), lus par l'application.
	@markdown path *.md
	header @markdown Content-Type "text/markdown; charset=utf-8"
	@gherkin path *.feature
	header @gherkin Content-Type "text/plain; charset=utf-8"

	file_server
}
