Skip to content

Commit 4e9cc18

Browse files
bgubijjk
andauthored
fix: don't fail with amp config in JS (#82798)
Because tsc doesn't infer string literal types in JS files --------- Co-authored-by: JJ Kasper <[email protected]>
1 parent c57fe25 commit 4e9cc18

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

packages/next/src/server/lib/router-utils/typegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export function generateValidatorFile(
475475
* Validated at build-time by parsePagesSegmentConfig.
476476
*/
477477
config?: {
478-
amp?: boolean | 'hybrid'
478+
amp?: boolean | 'hybrid' | string // necessary for JS
479479
maxDuration?: number
480480
runtime?: 'edge' | 'experimental-edge' | 'nodejs' | string // necessary unless config is exported as const
481481
regions?: string[]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useAmp } from 'next/amp'
2+
3+
export const config = { amp: 'hybrid' }
4+
5+
export default () => {
6+
const isAmp = useAmp()
7+
return `Hello ${isAmp ? 'AMP' : 'others'}`
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NextApiRequest, NextApiResponse } from 'next'
2+
3+
export const config = {
4+
api: {
5+
bodyParser: {
6+
sizeLimit: '5mb',
7+
},
8+
},
9+
}
10+
11+
export default (req: NextApiRequest, res: NextApiResponse) => {
12+
res.status(200).json(req.body)
13+
}

0 commit comments

Comments
 (0)