# SITE_ADDRESS is the domain list, e.g. "robotmarkets.ir, www.robotmarkets.ir" (automatic HTTPS),
# or ":80" for plain HTTP behind another proxy or for a local test.
{$SITE_ADDRESS::80} {
	root * /srv
	# The defaults cover text and JSON; the binary buildings file compresses to about 60% too.
	encode {
		zstd
		gzip
		match {
			# Repeated values for the same header are OR-ed.
			header Content-Type text/*
			header Content-Type application/json*
			header Content-Type application/javascript*
			header Content-Type application/manifest+json*
			header Content-Type image/svg+xml*
			header Content-Type application/octet-stream*
		}
	}

	# Hashed build files never change; the page, service worker and manifest must always be revalidated
	# so installed copies pick up new versions.
	@hashed path /assets/*
	header @hashed Cache-Control "public, max-age=31536000, immutable"
	@fresh path / /index.html /sw.js /manifest.webmanifest
	header @fresh Cache-Control "no-cache"
	# Map data and satellite tiles only change with a new map build.
	@mapdata path /imagery/* /data/*
	header @mapdata Cache-Control "public, max-age=604800"
	@manifest path /manifest.webmanifest
	header @manifest Content-Type "application/manifest+json"

	header {
		X-Content-Type-Options nosniff
		Referrer-Policy strict-origin-when-cross-origin
		# Real-world mode needs location and the compass; the camera is reserved for the AR phase.
		Permissions-Policy "geolocation=(self), camera=(self), accelerometer=(self), gyroscope=(self), magnetometer=(self)"
		-Server
	}

	try_files {path} /index.html
	file_server
}
