chore(i18n): 防 matcher 漏排 backend rewrite 再翻车#336
Merged
longsizhuo merged 1 commit intomainfrom May 6, 2026
Merged
Conversation
PR #335 修了登录炸的 hotfix(next-intl middleware matcher 漏排 /oauth /auth /analytics 三条 rewrite-to-backend 路径)。补防御让同 样的 bug 不再发生: 1. tests/proxy-matcher.test.ts - 静态扫 next.config.mjs 提取所有 rewrites() 函数体内的 source - 解析 proxy.ts matcher 字符串里 negative-lookahead 的排除组 - 对每个 source 第一段 path,断言它在排除组里 - 用 test.each 每条 source 一个 case,错误信息直接指引修法 - 加新 rewrite 不带 /api/ 前缀但忘改 matcher → CI fail 2. dev_docs/i18n_url_routing.md - 新章节「加新 backend rewrite」直接告诉以后写代码的人: 新增 next.config rewrite 必须同步更新 proxy.ts matcher - 列了 PR #335 事故 + 正确流程示例 跑了 pnpm test 19 个 case 全过(含 16 条现有 rewrite + 2 sanity check)。
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
PR #335 修了登录炸的 hotfix ——
proxy.ts的 next-intl matcher 漏排/oauth /auth /analytics三条 rewrite-to-backend 路径,导致/oauth/render/github被 redirect 到/en/oauth/...→ rewrite 不匹配 → 404 → 登录全员失败。按 hotfix 的根因分析,这个 bug 模式还会再发生:任何人加新
next.config.mjsrewrite source 不带/api/前缀但忘了改proxy.tsmatcher,登录链 / OAuth / 后端 API 直通的某条路径就会被 i18n middleware 误吃。防御
1.
tests/proxy-matcher.test.ts(新增)静态扫
next.config.mjs拿到所有 rewritesource列表,解析proxy.tsmatcher 的 negative-lookahead 排除组,对每条 source 的第一段 path 断言它在排除组里:跑过的:16 条现有 rewrite + 2 sanity check (
exclusions有api/_next、能扫到 sources),全过。2.
dev_docs/i18n_url_routing.md新章节「加新 backend rewrite」直接告诉后来人:
附 PR #335 事故链 + 正确流程示例。
排查结果
把
next.config.mjs所有 16 条 rewrite source 跑一遍,确认 #335 hotfix 之后没有遗漏:apiauthanalyticsapioauthapiapiapiapiTest plan
pnpm test19 case 全过oauth)确认 CI fail(可在 review 时验证)/foobar/:path*不动 matcher → 验证 CI fail