diff --git a/packages/next/src/build/analysis/get-page-static-info.ts b/packages/next/src/build/analysis/get-page-static-info.ts index f4dc24a74893..4b465cccb669 100644 --- a/packages/next/src/build/analysis/get-page-static-info.ts +++ b/packages/next/src/build/analysis/get-page-static-info.ts @@ -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 diff --git a/test/e2e/edge-configurable-runtime/app/src/pages/api/edge.js b/test/e2e/edge-configurable-runtime/app/src/pages/api/edge.js new file mode 100644 index 000000000000..beac5edf5a72 --- /dev/null +++ b/test/e2e/edge-configurable-runtime/app/src/pages/api/edge.js @@ -0,0 +1,2 @@ +export default () => new Response('ok') +export const config = { runtime: 'edge' } diff --git a/test/e2e/edge-configurable-runtime/app/src/pages/index.jsx b/test/e2e/edge-configurable-runtime/app/src/pages/index.jsx new file mode 100644 index 000000000000..dc344c3effb9 --- /dev/null +++ b/test/e2e/edge-configurable-runtime/app/src/pages/index.jsx @@ -0,0 +1 @@ +export default () =>

hello world

diff --git a/test/e2e/edge-configurable-runtime/index.test.ts b/test/e2e/edge-configurable-runtime/index.test.ts index 9d93f70c60dd..75bbd2529082 100644 --- a/test/e2e/edge-configurable-runtime/index.test.ts +++ b/test/e2e/edge-configurable-runtime/index.test.ts @@ -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', () => {