Skip to content

Commit 95caa87

Browse files
authored
fix: Pages router API routes with Next 14 (#453)
1 parent 161a5f7 commit 95caa87

File tree

6 files changed

+64
-46
lines changed

6 files changed

+64
-46
lines changed

.changeset/pretty-lamps-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: Pages router API routes with Next 14

examples/playground14/e2e/base.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ test.describe("playground/base", () => {
5252
await expect(res.json()).resolves.toEqual({ nextUrl: expectedURL, url: expectedURL });
5353
});
5454

55+
test("Pages router API routes", async ({ page }) => {
56+
const res = await page.request.get("/api/pages");
57+
expect(await res.json()).toEqual({ hello: "world" });
58+
});
59+
5560
test("generates an og image successfully", async ({ page }) => {
5661
const res = await page.request.get("/og");
5762
expect(res.status()).toEqual(200);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
type Data = {
4+
hello: string;
5+
};
6+
7+
export default function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
8+
res.status(200).json({ hello: "world" });
9+
}

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"vitest": "catalog:"
7272
},
7373
"dependencies": {
74-
"@ast-grep/napi": "^0.34.1",
74+
"@ast-grep/napi": "^0.36.1",
7575
"@dotenvx/dotenvx": "catalog:",
7676
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@756",
7777
"enquirer": "^2.4.1",

packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ export function inlineDynamicRequires(updater: ContentUpdater, buildOpts: BuildO
4747
updater.updateContent(
4848
"inline-node-module-loader",
4949
{
50-
filter: getCrossPlatformPathRegex(
51-
String.raw`/next/dist/server/lib/module-loader/node-module-loader\.js$`,
52-
{ escape: false }
53-
),
50+
filter: getCrossPlatformPathRegex(String.raw`/module-loader/node-module-loader\.js$`, {
51+
escape: false,
52+
}),
5453
contentFilter: /class NodeModuleLoader {/,
5554
},
5655
async ({ contents }) => patchCode(contents, await getNodeModuleLoaderRule(buildOpts))

pnpm-lock.yaml

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)