Skip to content

fix(hotdocs): SSR fetch 加 InvolutionHell-SSR UA 让 CF 放行#327

Merged
longsizhuo merged 1 commit intomainfrom
fix/hotdocs-cf-ua
Apr 27, 2026
Merged

fix(hotdocs): SSR fetch 加 InvolutionHell-SSR UA 让 CF 放行#327
longsizhuo merged 1 commit intomainfrom
fix/hotdocs-cf-ua

Conversation

@longsizhuo
Copy link
Copy Markdown
Member

故障

首页右上角 Hot This Week / 本周最热 一直 "暂无数据"。
(用户截图说"Top Rank 是空的"实际是看花眼了——左侧 Top Rank 早就有 TSK-Glofy 130 PTS / 0dysseus13 100 / duang3457 80 三张卡片,空的是右侧 Hot Docs 区块。)

根因

直接 `curl https://api.involutionhell.com/analytics/top-docs?window=7d&limit=5\` 200 + 5 条数据正常。
`HotDocsPreview.tsx` 的 SSR fetch 没带 UA header,Vercel runner 默认 `node` UA 不匹配你 CF 的 Custom Rule(`UA contains "InvolutionHell-SSR" → Skip Bot Fight`),按 IP 信誉被拦下回 403/empty → catch 返 `[]` → "暂无数据"。

代码库其他 SSR fetcher 都已经带 `InvolutionHell-SSR/1.0` UA:

  • `fetchProfile` (app/u/[username]/page.tsx)
  • `fetchEvents` (app/events/page.tsx, lib/events-fetch.ts)
  • `fetchEventDetail` (app/events/[id]/page.tsx)
  • `fetchLinks` (app/feed/page.tsx)

唯独 HotDocsPreview 漏了。本 PR 补齐。

Test plan

  • tsc 通过
  • lint-staged 通过
  • merge 后 prod redeploy → 首页 "Hot This Week" 显示 5 条文档

故障
首页右侧 "Hot This Week / 本周最热" 一直显示 "暂无数据"。
直接 curl 后端 /analytics/top-docs 是 200 + 5 条数据正常。

根因
其他 SSR fetcher(fetchProfile / events / feed)都带
"InvolutionHell-SSR/1.0 (+https://involutionhell.com)" UA,匹配 CF Custom
Rule 跳过 Bot Fight。HotDocsPreview 之前没加 header,Vercel runner 默认
"node" UA 不匹配规则,按 IP 信誉被拦回 403/empty → catch 返 [] → "暂无数据"。

本 PR
跟其他 SSR fetcher 完全对齐,加 accept + user-agent header。
Copilot AI review requested due to automatic review settings April 27, 2026 16:18
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
involutionhell-github-io Building Building Preview, Comment Apr 27, 2026 4:18pm
website-preview Building Building Preview, Comment Apr 27, 2026 4:18pm

@longsizhuo longsizhuo merged commit 1d18dc9 into main Apr 27, 2026
6 of 8 checks passed
@longsizhuo longsizhuo deleted the fix/hotdocs-cf-ua branch April 27, 2026 16:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the homepage “Hot This Week / 本周最热” SSR data fetch being blocked by Cloudflare by adding the expected SSR User-Agent token so CF custom rules can allow the request through.

Changes:

  • Add User-Agent: InvolutionHell-SSR/1.0 (+https://involutionhell.com) to the Hot Docs SSR fetch request.
  • Add Accept: application/json header (consistent with other SSR fetchers) and document the Cloudflare rationale inline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants