Skip to content

Commit b7b9392

Browse files
authored
feat: support edge runtime key (#2036)
* feat: add support for edge key * feat: refactor * feat: switch demos to edge * fix: add helper function
1 parent b64da2f commit b7b9392

File tree

35 files changed

+41
-39
lines changed

35 files changed

+41
-39
lines changed

demos/default/pages/api/og.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ImageResponse } from '@vercel/og'
22
import { NextRequest } from 'next/server'
33

44
export const config = {
5-
runtime: 'experimental-edge',
5+
runtime: 'edge',
66
}
77

88
export default async function handler(req: NextRequest) {

demos/middleware/pages/api/edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const config = {
2-
runtime: 'experimental-edge',
2+
runtime: 'edge',
33
}
44

55
export default (req) => new Response('Hello world!')

packages/runtime/src/helpers/analysis.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const enum ApiRouteType {
1111

1212
export interface ApiStandardConfig {
1313
type?: never
14-
runtime?: 'nodejs' | 'experimental-edge'
14+
runtime?: 'nodejs' | 'experimental-edge' | 'edge'
1515
schedule?: never
1616
}
1717

@@ -29,6 +29,8 @@ export interface ApiBackgroundConfig {
2929

3030
export type ApiConfig = ApiStandardConfig | ApiScheduledConfig | ApiBackgroundConfig
3131

32+
export const isEdgeConfig = (config: string) => ['experimental-edge', 'edge'].includes(config)
33+
3234
export const validateConfigValue = (config: ApiConfig, apiFilePath: string): config is ApiConfig => {
3335
if (config.type === ApiRouteType.SCHEDULED) {
3436
if (!config.schedule) {
@@ -39,7 +41,7 @@ export const validateConfigValue = (config: ApiConfig, apiFilePath: string): con
3941
)
4042
return false
4143
}
42-
if ((config as ApiConfig).runtime === 'experimental-edge') {
44+
if (isEdgeConfig((config as ApiConfig).runtime)) {
4345
console.error(
4446
`Invalid config value in ${relative(
4547
process.cwd(),
@@ -60,7 +62,7 @@ export const validateConfigValue = (config: ApiConfig, apiFilePath: string): con
6062
)
6163
return false
6264
}
63-
if (config.type && (config as ApiConfig).runtime === 'experimental-edge') {
65+
if (config.type && isEdgeConfig((config as ApiConfig).runtime)) {
6466
console.error(
6567
`Invalid config value in ${relative(
6668
process.cwd(),

packages/runtime/src/helpers/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getApiHandler } from '../templates/getApiHandler'
2020
import { getHandler } from '../templates/getHandler'
2121
import { getResolverForPages, getResolverForSourceFiles } from '../templates/getPageResolver'
2222

23-
import { ApiConfig, ApiRouteType, extractConfigFromFile } from './analysis'
23+
import { ApiConfig, ApiRouteType, extractConfigFromFile, isEdgeConfig } from './analysis'
2424
import { getSourceFileForPage } from './files'
2525
import { writeFunctionConfiguration } from './functionsMetaData'
2626
import { getFunctionNameForPage } from './utils'
@@ -43,7 +43,7 @@ export const generateFunctions = async (
4343

4444
for (const { route, config, compiled } of apiRoutes) {
4545
// Don't write a lambda if the runtime is edge
46-
if (config.runtime === 'experimental-edge') {
46+
if (isEdgeConfig(config.runtime)) {
4747
continue
4848
}
4949
const apiHandlerSource = await getApiHandler({
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
experimental: {
33
appDir: true,
4-
runtime: 'experimental-edge',
4+
runtime: 'edge',
55
},
66
}

test/e2e/app-dir/app-edge/app/app-edge/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export default function Page() {
55
return <p>Node!</p>
66
}
77

8-
export const runtime = 'experimental-edge'
8+
export const runtime = 'edge'

test/e2e/app-dir/app-edge/pages/pages-edge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export default function Page() {
22
return <p>pages-edge-ssr</p>
33
}
44

5-
export const config = { runtime: 'experimental-edge' }
5+
export const config = { runtime: 'edge' }

test/e2e/app-dir/app-middleware/pages/api/dump-headers-edge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const config = {
2-
runtime: 'experimental-edge',
2+
runtime: 'edge',
33
}
44

55
export default (req) => {

test/e2e/app-dir/app/app/(rootonly)/dashboard/hello/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export default function HelloPage(props) {
66
)
77
}
88

9-
export const runtime = 'experimental-edge'
9+
export const runtime = 'edge'

test/e2e/app-dir/app/app/dashboard/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export default function DashboardPage(props) {
1313
)
1414
}
1515

16-
export const runtime = 'experimental-edge'
16+
export const runtime = 'edge'

0 commit comments

Comments
 (0)