Skip to content

Commit 4f06bf6

Browse files
fix(docs): resolveDocPath 放宽超时+SSR UA+失败日志,修生产 404 自愈失效
resolveDocPath 的 fetch 之前 400ms 超时太紧、catch 静默无日志, 导致 Vercel SSR 调后端 resolve 拿不到结果时静默降级 404,服务端 308 自愈在生产不生效(DB/后端/数据均已验证正常)。 - 超时 400ms → 2500ms(Vercel→CF→Oracle 跨区+冷缓存留余量) - 加 SSR UA + accept header(对齐 feed/page,规避 CF bot filter) - catch 与非 3xx 分支加 console.error(status/cf-ray/error), 便于从 Vercel 运行时日志定位真实失败原因
1 parent 04ec76e commit 4f06bf6

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

app/[locale]/docs/[...slug]/page.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ async function resolveDocPath(
3939
const strippedPath = `/docs/${slug.join("/")}`;
4040
try {
4141
const controller = new AbortController();
42-
const timeout = setTimeout(() => controller.abort(), 400);
42+
// 跨区(Vercel→CF→Oracle)+ 后端冷缓存可能 >1s,400ms 太紧会误降级 404
43+
const timeout = setTimeout(() => controller.abort(), 2500);
4344
const res = await fetch(
4445
`${BACKEND_URL}/api/docs/resolve?path=${encodeURIComponent(strippedPath)}`,
45-
{ redirect: "manual", signal: controller.signal, cache: "no-store" },
46+
{
47+
redirect: "manual",
48+
signal: controller.signal,
49+
cache: "no-store",
50+
// 显式 UA:Vercel SSR 默认出口 UA 可能被 CF bot filter 拦(对齐 feed/page fetchLinks)
51+
headers: {
52+
accept: "application/json",
53+
"user-agent": "InvolutionHell-SSR/1.0 (+https://involutionhell.com)",
54+
},
55+
},
4656
);
4757
clearTimeout(timeout);
4858
if (res.status === 301 || res.status === 308) {
@@ -51,9 +61,21 @@ async function resolveDocPath(
5161
if (loc && loc !== strippedPath) {
5262
return `/${locale}${loc}`;
5363
}
64+
return null;
5465
}
55-
} catch {
56-
// 超时或后端不可达:降级到 notFound()
66+
// 非 3xx:记录真实状态,便于从 Vercel 日志定位(CF 403 / 后端异常等)
67+
console.error("[docs/resolve] non-redirect status", {
68+
path: strippedPath,
69+
status: res.status,
70+
cfRay: res.headers.get("cf-ray"),
71+
});
72+
} catch (err) {
73+
// 超时(AbortError)或后端不可达:记录后降级 notFound()
74+
console.error("[docs/resolve] fetch failed", {
75+
path: strippedPath,
76+
backend: BACKEND_URL,
77+
error: err instanceof Error ? `${err.name}: ${err.message}` : String(err),
78+
});
5779
}
5880
return null;
5981
}

0 commit comments

Comments
 (0)