(req, res, next)
| 24 | // /jp* -> /ja* |
| 25 | // /zh-TW* -> /zh* |
| 26 | export default function languageCodeRedirects(req, res, next) { |
| 27 | // Only in the unlikely event that the `req.path` starts with one of these |
| 28 | // prefixes do we bother looking up what the redirect should be. |
| 29 | if (req.path.startsWith('/_next/static')) return next() |
| 30 | if (!combinedRedirectPatternRegex) return next() |
| 31 | if (!combinedRedirectPatternRegex.test(req.path)) return next() |
| 32 | |
| 33 | // This loop is almost never ever used so it doesn't have to be |
| 34 | // particularly smart or fast. |
| 35 | const [code, pattern] = allRedirectPatterns.find(([, pattern]) => pattern.test(req.path)) |
| 36 | if (code && pattern) { |
| 37 | defaultCacheControl(res) |
| 38 | return res.redirect(301, req.path.replace(pattern, `/${code}`)) |
| 39 | } |
| 40 | return next() |
| 41 | } |
nothing calls this directly
no test coverage detected