UNPKG

36.3 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../lib/load-custom-routes.ts"],"names":["allowedStatusCodes","Set","allowedHasTypes","namedGroupsRegex","getRedirectStatus","route","statusCode","permanent","PERMANENT_REDIRECT_STATUS","TEMPORARY_REDIRECT_STATUS","normalizeRouteRegex","regex","replace","checkRedirect","invalidParts","hadInvalidStatus","has","push","checkHeader","Array","isArray","headers","header","key","value","tryParsePath","handleUrl","result","routePath","parsedDestination","pathname","hash","tokens","pathToRegexp","parse","tokensToRegexp","err","errMatches","message","match","position","parseInt","console","error","fill","join","checkCustomRoutes","routes","type","process","exit","numInvalidRoutes","hadInvalidHas","allowedKeys","add","JSON","stringify","basePath","destination","startsWith","source","keys","Object","invalidKeys","filter","locale","invalidHasItems","hasItem","invalidHasParts","length","itemStr","_route","sourceTokens","hasSegments","matchAll","unnamedInDest","token","name","unnamedIndex","RegExp","size","destTokens","destinationParseFailed","sourceSegments","map","item","Boolean","invalidDestSegments","hasInvalidKeys","hasInvalidParts","processRoutes","config","_routes","newRoutes","defaultLocales","i18n","domains","defaultLocale","base","http","domain","r","srcBasePath","isExternal","destBasePath","forEach","locales","trailingSlash","loadRedirects","redirects","loadRewrites","rewrites","beforeFiles","afterFiles","fallback","_rewrites","every","loadHeaders","loadCustomRoutes","Promise","all","unshift","undefined","internal"],"mappings":"oMAAA,wBAEA,uFACA,mGACA,uD,w4BA4CO,KAAMA,CAAAA,kBAAkB,CAAG,GAAIC,CAAAA,GAAJ,CAAQ,CAAC,GAAD,CAAM,GAAN,CAAW,GAAX,CAAgB,GAAhB,CAAqB,GAArB,CAAR,CAA3B,C,8CACP,KAAMC,CAAAA,eAAe,CAAG,GAAID,CAAAA,GAAJ,CAAQ,CAAC,QAAD,CAAW,QAAX,CAAqB,OAArB,CAA8B,MAA9B,CAAR,CAAxB,CACA,KAAME,CAAAA,gBAAgB,CAAG,+BAAzB,CAEO,QAASC,CAAAA,iBAAT,CAA2BC,KAA3B,CAGI,CACT,MACE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AAClC,QAAX,CAAqB,CACnBoD,SAAS,CAACY,OAAV,CAAkB,CAChB7D,MAAM,CAAE+B,MAAM,CAAClC,QAAP,CAAkB,GADV,CAEhBC,WAAW,CAAEiC,MAAM,CAAClC,QAFJ,CAGhBlD,SAAS,CAAE,IAHK,CAIhBkD,QAAQ,CAAE,KAJM,CAKhBQ,MAAM,CAAE0B,MAAM,CAACI,IAAP,CAAc,KAAd,CAAsB2B,SALd,CAMhBC,QAAQ,CAAE,IANM,CAAlB,EAQD,CACF,CAED,MAAO,CACLtG,OADK,CAEL0F,QAFK,CAGLF,SAHK,CAAP,CAKD","sourcesContent":["import { parse as parseUrl } from 'url'\nimport { NextConfig } from '../next-server/server/config'\nimport * as pathToRegexp from 'next/dist/compiled/path-to-regexp'\nimport escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'\nimport {\n PERMANENT_REDIRECT_STATUS,\n TEMPORARY_REDIRECT_STATUS,\n} from '../next-server/lib/constants'\n\nexport type RouteHas =\n | {\n type: 'header' | 'query' | 'cookie'\n key: string\n value?: string\n }\n | {\n type: 'host'\n key?: undefined\n value: string\n }\n\nexport type Rewrite = {\n source: string\n destination: string\n basePath?: false\n locale?: false\n has?: RouteHas[]\n}\n\nexport type Header = {\n source: string\n basePath?: false\n locale?: false\n headers: Array<{ key: string; value: string }>\n has?: RouteHas[]\n}\n\n// internal type used for validation (not user facing)\nexport type Redirect = {\n source: string\n destination: string\n basePath?: false\n locale?: false\n has?: RouteHas[]\n statusCode?: number\n permanent?: boolean\n}\n\nexport const allowedStatusCodes = new Set([301, 302, 303, 307, 308])\nconst allowedHasTypes = new Set(['header', 'cookie', 'query', 'host'])\nconst namedGroupsRegex = /\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>/g\n\nexport function getRedirectStatus(route: {\n statusCode?: number\n permanent?: boolean\n}): number {\n return (\n route.statusCode ||\n (route.permanent ? PERMANENT_REDIRECT_STATUS : TEMPORARY_REDIRECT_STATUS)\n )\n}\n\nexport function normalizeRouteRegex(regex: string) {\n // clean up un-necessary escaping from regex.source which turns / into \\\\/\n return regex.replace(/\\\\\\//g, '/')\n}\n\nfunction checkRedirect(\n route: Redirect\n): { invalidParts: string[]; hadInvalidStatus: boolean } {\n const invalidParts: string[] = []\n let hadInvalidStatus: boolean = false\n\n if (route.statusCode && !allowedStatusCodes.has(route.statusCode)) {\n hadInvalidStatus = true\n invalidParts.push(`\\`statusCode\\` is not undefined or valid statusCode`)\n }\n if (typeof route.permanent !== 'boolean' && !route.statusCode) {\n invalidParts.push(`\\`permanent\\` is not set to \\`true\\` or \\`false\\``)\n }\n\n return {\n invalidParts,\n hadInvalidStatus,\n }\n}\n\nfunction checkHeader(route: Header): string[] {\n const invalidParts: string[] = []\n\n if (!Array.isArray(route.headers)) {\n invalidParts.push('`headers` field must be an array')\n } else {\n for (const header of route.headers) {\n if (!header || typeof header !== 'object') {\n invalidParts.push(\n \"`headers` items must be object with { key: '', value: '' }\"\n )\n break\n }\n if (typeof header.key !== 'string') {\n invalidParts.push('`key` in header item must be string')\n break\n }\n if (typeof header.value !== 'string') {\n invalidParts.push('`value` in header item must be string')\n break\n }\n }\n }\n return invalidParts\n}\n\ntype ParseAttemptResult = {\n error?: boolean\n tokens?: pathToRegexp.Token[]\n}\n\nfunction tryParsePath(route: string, handleUrl?: boolean): ParseAttemptResult {\n const result: ParseAttemptResult = {}\n let routePath = route\n\n try {\n if (handleUrl) {\n const parsedDestination = parseUrl(route, true)\n routePath = `${parsedDestination.pathname!}${\n parsedDestination.hash || ''\n }`\n }\n\n // Make sure we can parse the source properly\n result.tokens = pathToRegexp.parse(routePath)\n pathToRegexp.tokensToRegexp(result.tokens)\n } catch (err) {\n // If there is an error show our error link but still show original error or a formatted one if we can\n const errMatches = err.message.match(/at (\\d{0,})/)\n\n if (errMatches) {\n const position = parseInt(errMatches[1], 10)\n console.error(\n `\\nError parsing \\`${route}\\` ` +\n `https://nextjs.org/docs/messages/invalid-route-source\\n` +\n `Reason: ${err.message}\\n\\n` +\n ` ${routePath}\\n` +\n ` ${new Array(position).fill(' ').join('')}^\\n`\n )\n } else {\n console.error(\n `\\nError parsing ${route} https://nextjs.org/docs/messages/invalid-route-source`,\n err\n )\n }\n result.error = true\n }\n\n return result\n}\n\nexport type RouteType = 'rewrite' | 'redirect' | 'header'\n\nfunction checkCustomRoutes(\n routes: Redirect[] | Header[] | Rewrite[],\n type: RouteType\n): void {\n if (!Array.isArray(routes)) {\n console.error(\n `Error: ${type}s must return an array, received ${typeof routes}.\\n` +\n `See here for more info: https://nextjs.org/docs/messages/routes-must-be-array`\n )\n process.exit(1)\n }\n\n let numInvalidRoutes = 0\n let hadInvalidStatus = false\n let hadInvalidHas = false\n\n const allowedKeys = new Set<string>(['source', 'basePath', 'locale', 'has'])\n\n if (type === 'rewrite') {\n allowedKeys.add('destination')\n }\n if (type === 'redirect') {\n allowedKeys.add('statusCode')\n allowedKeys.add('permanent')\n allowedKeys.add('destination')\n }\n if (type === 'header') {\n allowedKeys.add('headers')\n }\n\n for (const route of routes) {\n if (!route || typeof route !== 'object') {\n console.error(\n `The route ${JSON.stringify(\n route\n )} is not a valid object with \\`source\\` and \\`${\n type === 'header' ? 'headers' : 'destination'\n }\\``\n )\n numInvalidRoutes++\n continue\n }\n\n if (\n type === 'rewrite' &&\n (route as Rewrite).basePath === false &&\n !(\n (route as Rewrite).destination.startsWith('http://') ||\n (route as Rewrite).destination.startsWith('https://')\n )\n ) {\n console.error(\n `The route ${\n (route as Rewrite).source\n } rewrites urls outside of the basePath. Please use a destination that starts with \\`http://\\` or \\`https://\\` https://nextjs.org/docs/messages/invalid-external-rewrite`\n )\n numInvalidRoutes++\n continue\n }\n\n const keys = Object.keys(route)\n const invalidKeys = keys.filter((key) => !allowedKeys.has(key))\n const invalidParts: string[] = []\n\n if (typeof route.basePath !== 'undefined' && route.basePath !== false) {\n invalidParts.push('`basePath` must be undefined or false')\n }\n\n if (typeof route.locale !== 'undefined' && route.locale !== false) {\n invalidParts.push('`locale` must be undefined or false')\n }\n\n if (typeof route.has !== 'undefined' && !Array.isArray(route.has)) {\n invalidParts.push('`has` must be undefined or valid has object')\n hadInvalidHas = true\n } else if (route.has) {\n const invalidHasItems = []\n\n for (const hasItem of route.has) {\n let invalidHasParts = []\n\n if (!allowedHasTypes.has(hasItem.type)) {\n invalidHasParts.push(`invalid type \"${hasItem.type}\"`)\n }\n if (typeof hasItem.key !== 'string' && hasItem.type !== 'host') {\n invalidHasParts.push(`invalid key \"${hasItem.key}\"`)\n }\n if (\n typeof hasItem.value !== 'undefined' &&\n typeof hasItem.value !== 'string'\n ) {\n invalidHasParts.push(`invalid value \"${hasItem.value}\"`)\n }\n if (typeof hasItem.value === 'undefined' && hasItem.type === 'host') {\n invalidHasParts.push(`value is required for \"host\" type`)\n }\n\n if (invalidHasParts.length > 0) {\n invalidHasItems.push(\n `${invalidHasParts.join(', ')} for ${JSON.stringify(hasItem)}`\n )\n }\n }\n\n if (invalidHasItems.length > 0) {\n hadInvalidHas = true\n const itemStr = `item${invalidHasItems.length === 1 ? '' : 's'}`\n\n console.error(\n `Invalid \\`has\\` ${itemStr}:\\n` + invalidHasItems.join('\\n')\n )\n console.error()\n invalidParts.push(`invalid \\`has\\` ${itemStr} found`)\n }\n }\n\n if (!route.source) {\n invalidParts.push('`source` is missing')\n } else if (typeof route.source !== 'string') {\n invalidParts.push('`source` is not a string')\n } else if (!route.source.startsWith('/')) {\n invalidParts.push('`source` does not start with /')\n }\n\n if (type === 'header') {\n invalidParts.push(...checkHeader(route as Header))\n } else {\n let _route = route as Rewrite | Redirect\n if (!_route.destination) {\n invalidParts.push('`destination` is missing')\n } else if (typeof _route.destination !== 'string') {\n invalidParts.push('`destination` is not a string')\n } else if (\n type === 'rewrite' &&\n !_route.destination.match(/^(\\/|https:\\/\\/|http:\\/\\/)/)\n ) {\n invalidParts.push(\n '`destination` does not start with `/`, `http://`, or `https://`'\n )\n }\n }\n\n if (type === 'redirect') {\n const result = checkRedirect(route as Redirect)\n hadInvalidStatus = hadInvalidStatus || result.hadInvalidStatus\n invalidParts.push(...result.invalidParts)\n }\n\n let sourceTokens: pathToRegexp.Token[] | undefined\n\n if (typeof route.source === 'string' && route.source.startsWith('/')) {\n // only show parse error if we didn't already show error\n // for not being a string\n const { tokens, error } = tryParsePath(route.source)\n\n if (error) {\n invalidParts.push('`source` parse failed')\n }\n sourceTokens = tokens\n }\n const hasSegments = new Set<string>()\n\n if (route.has) {\n for (const hasItem of route.has) {\n if (!hasItem.value && hasItem.key) {\n hasSegments.add(hasItem.key)\n }\n\n if (hasItem.value) {\n for (const match of hasItem.value.matchAll(namedGroupsRegex)) {\n if (match[1]) {\n hasSegments.add(match[1])\n }\n }\n\n if (hasItem.type === 'host') {\n hasSegments.add('host')\n }\n }\n }\n }\n\n // make sure no unnamed patterns are attempted to be used in the\n // destination as this can cause confusion and is not allowed\n if (typeof (route as Rewrite).destination === 'string') {\n if (\n (route as Rewrite).destination.startsWith('/') &&\n Array.isArray(sourceTokens)\n ) {\n const unnamedInDest = new Set()\n\n for (const token of sourceTokens) {\n if (typeof token === 'object' && typeof token.name === 'number') {\n const unnamedIndex = new RegExp(`:${token.name}(?!\\\\d)`)\n if ((route as Rewrite).destination.match(unnamedIndex)) {\n unnamedInDest.add(`:${token.name}`)\n }\n }\n }\n\n if (unnamedInDest.size > 0) {\n invalidParts.push(\n `\\`destination\\` has unnamed params ${[...unnamedInDest].join(\n ', '\n )}`\n )\n } else {\n const {\n tokens: destTokens,\n error: destinationParseFailed,\n } = tryParsePath((route as Rewrite).destination, true)\n\n if (destinationParseFailed) {\n invalidParts.push('`destination` parse failed')\n } else {\n const sourceSegments = new Set(\n sourceTokens\n .map((item) => typeof item === 'object' && item.name)\n .filter(Boolean)\n )\n const invalidDestSegments = new Set()\n\n for (const token of destTokens!) {\n if (\n typeof token === 'object' &&\n !sourceSegments.has(token.name) &&\n !hasSegments.has(token.name as string)\n ) {\n invalidDestSegments.add(token.name)\n }\n }\n\n if (invalidDestSegments.size) {\n invalidParts.push(\n `\\`destination\\` has segments not in \\`source\\` or \\`has\\` (${[\n ...invalidDestSegments,\n ].join(', ')})`\n )\n }\n }\n }\n }\n }\n\n const hasInvalidKeys = invalidKeys.length > 0\n const hasInvalidParts = invalidParts.length > 0\n\n if (hasInvalidKeys || hasInvalidParts) {\n console.error(\n `${invalidParts.join(', ')}${\n invalidKeys.length\n ? (hasInvalidParts ? ',' : '') +\n ` invalid field${invalidKeys.length === 1 ? '' : 's'}: ` +\n invalidKeys.join(',')\n : ''\n } for route ${JSON.stringify(route)}`\n )\n console.error()\n numInvalidRoutes++\n }\n }\n\n if (numInvalidRoutes > 0) {\n if (hadInvalidStatus) {\n console.error(\n `\\nValid redirect statusCode values are ${[...allowedStatusCodes].join(\n ', '\n )}`\n )\n }\n if (hadInvalidHas) {\n console.error(\n `\\nValid \\`has\\` object shape is ${JSON.stringify(\n {\n type: [...allowedHasTypes].join(', '),\n key: 'the key to check for',\n value: 'undefined or a value string to match against',\n },\n null,\n 2\n )}`\n )\n }\n console.error()\n console.error(\n `Error: Invalid ${type}${numInvalidRoutes === 1 ? '' : 's'} found`\n )\n process.exit(1)\n }\n}\n\nexport interface CustomRoutes {\n headers: Header[]\n rewrites: {\n fallback: Rewrite[]\n afterFiles: Rewrite[]\n beforeFiles: Rewrite[]\n }\n redirects: Redirect[]\n}\n\nfunction processRoutes<T>(\n routes: T,\n config: NextConfig,\n type: 'redirect' | 'rewrite' | 'header'\n): T {\n const _routes = (routes as any) as Array<{\n source: string\n locale?: false\n basePath?: false\n destination?: string\n }>\n const newRoutes: typeof _routes = []\n const defaultLocales: Array<{\n locale: string\n base: string\n }> = []\n\n if (config.i18n && type === 'redirect') {\n for (const item of config.i18n?.domains || []) {\n defaultLocales.push({\n locale: item.defaultLocale,\n base: `http${item.http ? '' : 's'}://${item.domain}`,\n })\n }\n\n defaultLocales.push({\n locale: config.i18n.defaultLocale,\n base: '',\n })\n }\n\n for (const r of _routes) {\n const srcBasePath =\n config.basePath && r.basePath !== false ? config.basePath : ''\n const isExternal = !r.destination?.startsWith('/')\n const destBasePath = srcBasePath && !isExternal ? srcBasePath : ''\n\n if (config.i18n && r.locale !== false) {\n defaultLocales.forEach((item) => {\n let destination\n\n if (r.destination) {\n destination = item.base\n ? `${item.base}${destBasePath}${r.destination}`\n : `${destBasePath}${r.destination}`\n }\n\n newRoutes.push({\n ...r,\n destination,\n source: `${srcBasePath}/${item.locale}${r.source}`,\n })\n })\n\n r.source = `/:nextInternalLocale(${config.i18n.locales\n .map((locale: string) => escapeStringRegexp(locale))\n .join('|')})${\n r.source === '/' && !config.trailingSlash ? '' : r.source\n }`\n\n if (r.destination && r.destination?.startsWith('/')) {\n r.destination = `/:nextInternalLocale${\n r.destination === '/' && !config.trailingSlash ? '' : r.destination\n }`\n }\n }\n r.source = `${srcBasePath}${r.source}`\n\n if (r.destination) {\n r.destination = `${destBasePath}${r.destination}`\n }\n newRoutes.push(r)\n }\n return (newRoutes as any) as T\n}\n\nasync function loadRedirects(config: NextConfig) {\n if (typeof config.redirects !== 'function') {\n return []\n }\n let redirects = await config.redirects()\n checkCustomRoutes(redirects, 'redirect')\n return processRoutes(redirects, config, 'redirect')\n}\n\nasync function loadRewrites(config: NextConfig) {\n if (typeof config.rewrites !== 'function') {\n return {\n beforeFiles: [],\n afterFiles: [],\n fallback: [],\n }\n }\n const _rewrites = await config.rewrites()\n let beforeFiles: Rewrite[] = []\n let afterFiles: Rewrite[] = []\n let fallback: Rewrite[] = []\n\n if (\n !Array.isArray(_rewrites) &&\n typeof _rewrites === 'object' &&\n Object.keys(_rewrites).every(\n (key) =>\n key === 'beforeFiles' || key === 'afterFiles' || key === 'fallback'\n )\n ) {\n beforeFiles = _rewrites.beforeFiles || []\n afterFiles = _rewrites.afterFiles || []\n fallback = _rewrites.fallback || []\n } else {\n afterFiles = _rewrites as any\n }\n\n checkCustomRoutes(beforeFiles, 'rewrite')\n checkCustomRoutes(afterFiles, 'rewrite')\n checkCustomRoutes(fallback, 'rewrite')\n\n return {\n beforeFiles: processRoutes(beforeFiles, config, 'rewrite'),\n afterFiles: processRoutes(afterFiles, config, 'rewrite'),\n fallback: processRoutes(fallback, config, 'rewrite'),\n }\n}\n\nasync function loadHeaders(config: NextConfig) {\n if (typeof config.headers !== 'function') {\n return []\n }\n let headers = await config.headers()\n checkCustomRoutes(headers, 'header')\n return processRoutes(headers, config, 'header')\n}\n\nexport default async function loadCustomRoutes(\n config: NextConfig\n): Promise<CustomRoutes> {\n const [headers, rewrites, redirects] = await Promise.all([\n loadHeaders(config),\n loadRewrites(config),\n loadRedirects(config),\n ])\n\n if (config.trailingSlash) {\n redirects.unshift(\n {\n source: '/:file((?!\\\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\\\.\\\\w+)/',\n destination: '/:file',\n permanent: true,\n locale: config.i18n ? false : undefined,\n internal: true,\n } as Redirect,\n {\n source: '/:notfile((?!\\\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\\\.]+)',\n destination: '/:notfile/',\n permanent: true,\n locale: config.i18n ? false : undefined,\n internal: true,\n } as Redirect\n )\n if (config.basePath) {\n redirects.unshift({\n source: config.basePath,\n destination: config.basePath + '/',\n permanent: true,\n basePath: false,\n locale: config.i18n ? false : undefined,\n internal: true,\n } as Redirect)\n }\n } else {\n redirects.unshift({\n source: '/:path+/',\n destination: '/:path+',\n permanent: true,\n locale: config.i18n ? false : undefined,\n internal: true,\n } as Redirect)\n if (config.basePath) {\n redirects.unshift({\n source: config.basePath + '/',\n destination: config.basePath,\n permanent: true,\n basePath: false,\n locale: config.i18n ? false : undefined,\n internal: true,\n } as Redirect)\n }\n }\n\n return {\n headers,\n rewrites,\n redirects,\n }\n}\n"]}
\No newline at end of file