Skip to content

Commit

Permalink
fix(#44077): allow edge runtime for api routes inside src/ folder (#4…
Browse files Browse the repository at this point in the history
…5093)

fixes: #44382
closes: #44882
closes: #44383
  • Loading branch information
feugy committed Jan 20, 2023
1 parent 9db8145 commit e8ae4e2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/build/analysis/get-page-static-info.ts
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
2 changes: 2 additions & 0 deletions 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' }
1 change: 1 addition & 0 deletions test/e2e/edge-configurable-runtime/app/src/pages/index.jsx
@@ -0,0 +1 @@
export default () => <p>hello world</p>
10 changes: 6 additions & 4 deletions test/e2e/edge-configurable-runtime/index.test.ts
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

0 comments on commit e8ae4e2

Please sign in to comment.