# ==============================================================================
# 上海炫恒网络系统有限公司 官网 —— 仅用 8081 端口提供服务
#
# 这个 Caddyfile 只负责把站点跑在容器内的 80 端口（宿主机映射到 8081），
# 不申请证书、不碰服务器的 80/443（那是 1Panel 的 Caddy 在用）。
# 等你在 1Panel 里把域名反代到 8081 之后，HTTPS 由 1Panel 那层处理。
# ==============================================================================
{
	# 关掉自动 HTTPS：本容器只做纯 HTTP 内网服务
	auto_https off
	admin off
}

:80 {
	root * /srv
	encode zstd gzip
	file_server

	# 无扩展名地址映射到 .html：
	#   /            -> /index.html
	#   /brands      -> /brands.html
	#   /assets/x.js -> 直接命中文件
	# 最后的 {path}/index.html 用来处理目录请求
	try_files {path} {path}.html {path}/index.html

	# 安全响应头（Caddy 默认会给静态文件加 X-Content-Type-Options: nosniff）
	header {
		X-Frame-Options "SAMEORIGIN"
		Referrer-Policy "strict-origin-when-cross-origin"
		Permissions-Policy "geolocation=(), microphone=(), camera=()"
		# 去掉会暴露版本信息的 Server 头
		-Server
	}

	# HTML 不缓存，保证改版后刷新即可见
	@html path *.html /
	header @html Cache-Control "no-cache, must-revalidate"

	# 带指纹不变的静态资源长缓存
	@assets path /assets/*
	header @assets Cache-Control "public, max-age=31536000, immutable"

	# 健康检查
	handle /healthz {
		respond "ok" 200
	}

	log {
		output file /var/log/caddy/access.log
		format console
	}

	# 纯静态站点没有后端，404 回首页兜底
	handle_errors {
		@404 expression {http.error.status_code} == 404
		rewrite @404 /index.html
		file_server
	}
}
