Nhật ký công việc cho nhiệm vụ "Thiết lập chuyển hướng vĩnh viễn đến các trang freecode.academy"

16 июн. 2026 г., 12:38:13

Đã xong. Commit.

if (
  (statusCode === 404 || ctx.pathname === '/404') &&
  ctx.req?.url &&
  ctx.res
) {
  const res = ctx.res

  const url = `https://freecode.academy${ctx.req.url}`

  const response = await fetch(url).catch(console.error)

  if (response?.ok) {
    res.writeHead(301, {
      Location: url,
    })
    res.end()
  }
}