Skip to content

fix: 讓 /{lang}/index.json 回傳字詞串列 (close #124)#125

Merged
bestian merged 2 commits into
mainfrom
fix/lang-index-json-route-124
Jun 4, 2026
Merged

fix: 讓 /{lang}/index.json 回傳字詞串列 (close #124)#125
bestian merged 2 commits into
mainfrom
fix/lang-index-json-route-124

Conversation

@bestian
Copy link
Copy Markdown
Contributor

@bestian bestian commented Jun 4, 2026

問題

以下四個路由原本應回傳字詞串列,但目前會被當成一般詞彙「index」查詢,查不到即回 404:

  • /a/index.json
  • /t/index.json
  • /h/index.json
  • /c/index.json

其中 /c/index.json 為萌典閃卡所使用,目前回傳 404。

修法(最小更動)

字詞串列其實已存在於 R2 的 {lang}/index.json,並已透過 /api/index/{lang}.json 對外提供。本 PR 在 handleLanguageSubRoute 加入 text === 'index' 的特例,直接回傳 R2 的 {lang}/index.json,行為與 /api/index/{lang}.json 對齊(找不到時回 404)。

測試

  • 新增整合測試:/{lang}/index.json 四個語系回傳陣列(tests/integration/api-index-xref-search.test.ts
  • 新增直接呼叫單元測試:成功回字詞串列 + 缺檔 404(tests/unit/api-handlers-direct.test.ts,符合 CLAUDE.md 對 handler 分支需 direct-call 覆蓋的要求)

驗證:typecheck ✅、lint ✅、test:unit(856 passed,覆蓋率 ratchet 維持)✅、test:integration(74 passed)✅

Close #124

🤖 Generated with Claude Code

bestian and others added 2 commits June 4, 2026 10:54
/a、/t、/h、/c 的 index.json 原本會被當成一般詞彙查詢,導致 404
(萌典閃卡使用的 /c/index.json 即受影響)。在 handleLanguageSubRoute
中加入 text === 'index' 的特例,直接回傳 R2 的 {lang}/index.json,
與 /api/index/{lang}.json 對齊。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
字詞串列原本以壓縮 JSON 回傳,全部擠在一行。改為 pretty 格式
(JSON.stringify(payload, null, 2)),每個詞彙獨立一行、逗號後換行,
排版較易閱讀。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bestian bestian merged commit 6ceafad into main Jun 4, 2026
5 checks passed
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.

待修理json路由中的/{lang}/index.json路由

1 participant