|
1 | 1 | /** |
2 | 2 | * Short URL handler for Nuxt error codes. |
3 | 3 | * |
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 |
6 | 6 | * |
7 | 7 | * 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. |
10 | 10 | */ |
11 | 11 | export default defineEventHandler((event) => { |
12 | 12 | const code = getRouterParam(event, 'code') |
13 | 13 |
|
14 | 14 | // 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)) { |
16 | 16 | throw createError({ statusCode: 404, statusMessage: 'Not found' }) |
17 | 17 | } |
18 | 18 |
|
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() |
21 | 21 |
|
22 | 22 | // TODO: update to /docs/5.x when Nuxt 5 is the default |
23 | 23 | return sendRedirect(event, `/docs/4.x/errors/${errorCode}`, 302) |
|
0 commit comments