把 404 頁接上未匹配的路徑 - #44
Merged
Merged
Conversation
hoshivel.com 上任何不存在的路徑都回一份零位元組的 404,瀏覽器把空 body 畫成 白頁、分頁標題退回原始 URL——看起來像整個站掛了,而不是路徑打錯。 原因不在頁面:src/pages/404.astro 在,四語文案也都在 src/i18n/ui.ts, astro build 一直寫出 dist/404.html(46 KB)。缺的是 wrangler.jsonc 的 assets.not_found_handling——預設值 "none" 對未匹配的請求回空 body, 從不打開 404.html。改為 "404-page"。 與姊妹站 sr-web 同一個缺陷、同一行修法;sr-web 已合併並部署驗過。理由見 workspace 的 decisions/infrastructure/Workers-靜態站要顯式開啟-404-頁.md。 test/not-found.test.mjs 釘住這一行,拿掉它第一條就紅。頁面文案不動——本站的 404 依 404.astro 檔頭的既有決定只用正體中文。
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.
hoshivel.com上任何不存在的路徑都回一份零位元組的 404。瀏覽器把空 body畫成白頁、分頁標題退回原始 URL——看起來像整個站掛了,而不是路徑打錯。
姊妹站 sr-web#64 是同一個缺陷、
同一行修法,已合併並部署驗過(
/zzz-not-here→404 15777)。原因不在頁面
src/pages/404.astro在,四語文案也都在src/i18n/ui.ts,astro build一直寫出
dist/404.html(46,185 bytes)。缺的是wrangler.jsonc的assets.not_found_handling:預設值"none"對未匹配的請求回空 body,從不打開
404.html。頁面在、產物在、部署成功——三者單獨看都正常,所以沒有任何一步會報錯。
改動
wrangler.jsonc:assets.not_found_handling設為"404-page"。這是修正本身。test/not-found.test.mjs:釘住上面那一行。拿掉它,第一條斷言就紅,其餘三條仍綠。README.md:〈部署〉記下這個鍵與本機的確認方式(埠取自本站的區塊 26820-26829)。.gitignore:.wrangler/(npx wrangler dev的本機狀態)。頁面文案不動。 本站的 404 依
404.astro檔頭的既有決定只用正體中文(
「靜態站無法從 Referer 可靠判斷語言,預設使用正體中文」);sr-web 那邊加了英文副標是因為它的檔頭註解本來就寫了要有,兩站在這一點上刻意不同。要不要統一
是另一個文案決定,不在本 PR。
驗證
本機以
npx wrangler dev跑 Workers 真正的資產路由,同一份dist/做 A/B,只差設定那一行:
"404-page"/zzz-not-here404 0404 46185/nope404 0404 46185/en/nope404 0404 46185/200 61327200 61327「不帶」那一欄與正式站現況一致。body 內含
<title>404 — Hoshivel</title>、這片夜空還沒有這顆星與返回首頁。hoshi test— 全部通過(17.8s)npm test— 20 passed(新增 4 條)astro check+astro build— 33 pages未動
src/i18n/,因此不需要npm run fonts。合併並部署後對正式站驗一次:
https://hoshivel.com/zzz-not-here要回404加非空的 body。