# Caddyfile — Cyrene AI 助手平台反向代理
# Caddy version: 2.x
# 环境变量: DOMAIN, ACME_EMAIL

{
	email {$ACME_EMAIL:admin@localhost}
	admin off
}

# 站点（DOMAIN 未设置时回退到 :80 HTTP）
{$DOMAIN::80} {
	log {
		output stdout
		format json
	}

	header {
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
		X-XSS-Protection "1; mode=block"
		Referrer-Policy "strict-origin-when-cross-origin"
		# 生产环境有域名时取消注释
		# Strict-Transport-Security "max-age=31536000; includeSubDomains"
		Strict-Transport-Security "max-age=31536000; includeSubDomains"
	}

	# WebSocket 路由
	handle_path /ws/* {
		reverse_proxy gateway:8080
	}

	# API 路由 → Gateway
	handle_path /api/* {
		reverse_proxy gateway:8080 {
			header_up Host {http.request.host}
			header_up X-Forwarded-For {http.request.remote.host}
			header_up X-Forwarded-Proto {http.request.scheme}
		}
	}

	# 前端静态文件
	handle {
		respond "Cyrene AI Platform — Frontend coming soon." 200
	}
}
