Files
cloudflare__vinext/tests/fixtures/pages-basic/pages/api/edge-hello.ts
James Anderson 15fbe66c47 test(pages-router): regression coverage for edge runtime & OG image API routes (#1338) (#1648)
Adds Pages Router fixtures and dev + production integration tests for the
two scenarios reported as failing in the Next.js Deploy Suite:

- `export const config = { runtime: 'edge' }` API route returns a Web
  Response (issue #1338 case 1 — edge API routes were observed as 500).
- `next/og` `ImageResponse` with `runtime: 'edge'` inside a Pages Router
  API route returns `image/png` (issue #1338 case 2 — OG routes were
  observed as 404).

Ports route handlers from `next.js/test/e2e/edge-pages-support/app/pages/api/hello.js`
and `next.js/test/e2e/og-api/app/pages/api/og.js`. The existing
implementation already wires both code paths correctly via
`handlePagesApiRoute` and the `vinext:og-inline-fetch-assets` plugin; this
PR locks in coverage so a Pages Router-only build cannot silently regress
either path.

Refs #1338
2026-05-28 15:58:51 +01:00

23 lines
878 B
TypeScript

// Ported from Next.js: test/e2e/edge-pages-support/app/pages/api/hello.js
// https://github.com/vercel/next.js/blob/canary/test/e2e/edge-pages-support/app/pages/api/hello.js
//
// Pages Router edge runtime API route. The handler receives a NextRequest
// (Fetch-style) instead of (req, res), and must return a Web Response.
// Regression coverage for cloudflare/vinext#1338 — edge runtime API routes
// were reported as returning 500 against the Next.js deploy suite.
export const config = {
runtime: "edge",
};
type NextRequestLike = Request & { nextUrl: { searchParams: URLSearchParams } };
export default async function handler(req: NextRequestLike): Promise<Response> {
return new Response(
JSON.stringify({
hello: "world",
query: Object.fromEntries(req.nextUrl.searchParams),
}),
{ headers: { "content-type": "application/json" } },
);
}