Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#44077): allow edge runtime for api routes inside src/ folder #45093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export async function getPageStaticInfo(params: {

const requiresServerRuntime = ssr || ssg || pageType === 'app'

const isAnAPIRoute = isAPIRoute(page?.replace(/^\/pages\//, '/'))
const isAnAPIRoute = isAPIRoute(page?.replace(/^(?:\/src)?\/pages\//, '/'))

resolvedRuntime = isEdgeRuntime(resolvedRuntime)
? resolvedRuntime
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default () => new Response('ok')
export const config = { runtime: 'edge' }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <p>hello world</p>
10 changes: 6 additions & 4 deletions test/e2e/edge-configurable-runtime/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { fetchViaHTTP, File, nextBuild } from 'next-test-utils'
import { join } from 'path'
import stripAnsi from 'strip-ansi'

const appDir = join(__dirname, './app')
const pagePath = 'pages/index.jsx'
const apiPath = 'pages/api/edge.js'
const page = new File(join(appDir, pagePath))
const api = new File(join(appDir, apiPath))

describe('Configurable runtime for pages and API routes', () => {
describe.each([
{ appDir: join(__dirname, './app/src'), title: 'src/pages and API routes' },
{ appDir: join(__dirname, './app'), title: 'pages and API routes' },
])('Configurable runtime for $title', ({ appDir }) => {
let next: NextInstance
const page = new File(join(appDir, pagePath))
const api = new File(join(appDir, apiPath))

if ((global as any).isNextDev) {
describe('In dev mode', () => {
Expand Down