MCPcopy Index your code
hub / github.com/github/docs / languageCodeRedirects

Function languageCodeRedirects

middleware/redirects/language-code-redirects.js:26–41  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

24// /jp* -> /ja*
25// /zh-TW* -> /zh*
26export 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}

Callers

nothing calls this directly

Calls 2

defaultCacheControlFunction · 0.90
nextFunction · 0.50

Tested by

no test coverage detected