-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into refactor/next-server
- Loading branch information
Showing
18 changed files
with
280 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ | |
"registry": "https://registry.npmjs.org/" | ||
} | ||
}, | ||
"version": "9.1.5" | ||
"version": "9.1.6-canary.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "create-next-app", | ||
"version": "9.1.5", | ||
"version": "9.1.6-canary.0", | ||
"keywords": [ | ||
"react", | ||
"next", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
export type Rewrite = { | ||
source: string | ||
destination: string | ||
} | ||
|
||
export type Redirect = Rewrite & { | ||
statusCode?: number | ||
} | ||
|
||
const allowedStatusCodes = new Set([301, 302, 303, 307, 308]) | ||
|
||
export default function checkCustomRoutes( | ||
routes: Array<Rewrite | Redirect>, | ||
type: 'redirect' | 'rewrite' | ||
): void { | ||
let numInvalidRoutes = 0 | ||
let hadInvalidStatus = false | ||
const isRedirect = type === 'redirect' | ||
const allowedKeys = new Set([ | ||
'source', | ||
'destination', | ||
...(isRedirect ? ['statusCode'] : []), | ||
]) | ||
|
||
for (const route of routes) { | ||
const keys = Object.keys(route) | ||
const invalidKeys = keys.filter(key => !allowedKeys.has(key)) | ||
const invalidParts = [] | ||
|
||
// TODO: investigate allowing RegExp directly | ||
if (!route.source) { | ||
invalidParts.push('`source` is missing') | ||
} else if (typeof route.source !== 'string') { | ||
invalidParts.push('`source` is not a string') | ||
} else if (!route.source.startsWith('/')) { | ||
invalidParts.push('`source` does not start with /') | ||
} | ||
|
||
if (!route.destination) { | ||
invalidParts.push('`destination` is missing') | ||
} else if (typeof route.destination !== 'string') { | ||
invalidParts.push('`destination` is not a string') | ||
} else if (!route.destination.startsWith('/')) { | ||
invalidParts.push('`destination` does not start with /') | ||
} | ||
|
||
if (isRedirect) { | ||
const redirRoute = route as Redirect | ||
|
||
if ( | ||
redirRoute.statusCode && | ||
!allowedStatusCodes.has(redirRoute.statusCode) | ||
) { | ||
hadInvalidStatus = true | ||
invalidParts.push(`\`statusCode\` is not undefined or valid statusCode`) | ||
} | ||
} | ||
|
||
const hasInvalidKeys = invalidKeys.length > 0 | ||
const hasInvalidParts = invalidParts.length > 0 | ||
|
||
if (hasInvalidKeys || hasInvalidParts) { | ||
console.error( | ||
`${invalidParts.join(', ')}${ | ||
invalidKeys.length | ||
? (hasInvalidParts ? ',' : '') + | ||
` invalid field${invalidKeys.length === 1 ? '' : 's'}: ` + | ||
invalidKeys.join(',') | ||
: '' | ||
} for route ${JSON.stringify(route)}` | ||
) | ||
numInvalidRoutes++ | ||
} | ||
} | ||
|
||
if (numInvalidRoutes > 0) { | ||
if (hadInvalidStatus) { | ||
console.error( | ||
`\nValid redirect statusCode values are ${[...allowedStatusCodes].join( | ||
', ' | ||
)}` | ||
) | ||
} | ||
console.error() | ||
|
||
throw new Error(`Invalid ${type}${numInvalidRoutes === 1 ? '' : 's'} found`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'hi' |
Oops, something went wrong.