Skip to content

Commit 397f8ba

Browse files
committed
fix: lowercase error codes in redirects to match content collection paths
1 parent 4f467fc commit 397f8ba

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

server/middleware/error-docs-redirect.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
*
44
* The Nuxt runtime links to https://nuxt.com/docs/errors/E1001 (unversioned).
55
* This middleware redirects those paths to the current default docs version
6-
* (e.g., /docs/4.x/errors/E1001) so the content can be resolved.
6+
* (e.g., /docs/4.x/errors/e1001) so the content can be resolved.
7+
*
8+
* The error code is lowercased to match the content collection path.
79
*/
810
export default defineEventHandler((event) => {
911
const path = getRequestURL(event).pathname
1012

1113
// Match /docs/errors/... but NOT /docs/3.x/errors/... or /docs/4.x/errors/...
1214
const match = path.match(/^\/docs\/errors\/(.+)$/)
13-
if (match) {
15+
if (match?.[1]) {
1416
// TODO: update to /docs/5.x when Nuxt 5 is the default
15-
return sendRedirect(event, `/docs/4.x/errors/${match[1]}`, 302)
17+
return sendRedirect(event, `/docs/4.x/errors/${match[1].toLowerCase()}`, 302)
1618
}
1719
})

server/routes/e/[code].get.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/**
22
* Short URL handler for Nuxt error codes.
33
*
4-
* Redirects /e/NUXT_E1001 → /docs/4.x/errors/E1001
5-
* Redirects /e/NUXT_B1001 → /docs/4.x/errors/B1001
4+
* Redirects /e/NUXT_E1001 → /docs/4.x/errors/e1001
5+
* Redirects /e/NUXT_B1001 → /docs/4.x/errors/b1001
66
*
77
* The error code format is NUXT_ followed by E or B and 1-4 digits.
8-
* The NUXT_ prefix is stripped and the user is redirected to the
9-
* current default docs version.
8+
* The NUXT_ prefix is stripped, the code is lowercased, and the user
9+
* is redirected to the current default docs version.
1010
*/
1111
export default defineEventHandler((event) => {
1212
const code = getRouterParam(event, 'code')
1313

1414
// Validate: must be NUXT_ followed by E or B and 1-4 digits
15-
if (!code || !/^NUXT_[EB]\d{1,4}$/.test(code)) {
15+
if (!code || !/^NUXT_[EB]\d{1,4}$/i.test(code)) {
1616
throw createError({ statusCode: 404, statusMessage: 'Not found' })
1717
}
1818

19-
// Strip the NUXT_ prefix → E1001 or B1001
20-
const errorCode = code.replace('NUXT_', '')
19+
// Strip the NUXT_ prefix and lowercase → e1001 or b1001
20+
const errorCode = code.replace('NUXT_', '').toLowerCase()
2121

2222
// TODO: update to /docs/5.x when Nuxt 5 is the default
2323
return sendRedirect(event, `/docs/4.x/errors/${errorCode}`, 302)

0 commit comments

Comments
 (0)