From 4a73df4da7b5a0b2ab5389de18273392922553b7 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Fri, 10 Oct 2025 13:43:40 +0200 Subject: [PATCH 1/4] fix: Ensure dynamic routes are excluded in getStaticAPIRoutes --- packages/open-next/src/core/routing/routeMatcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/open-next/src/core/routing/routeMatcher.ts b/packages/open-next/src/core/routing/routeMatcher.ts index 788685ad0..89b1f202e 100644 --- a/packages/open-next/src/core/routing/routeMatcher.ts +++ b/packages/open-next/src/core/routing/routeMatcher.ts @@ -86,8 +86,8 @@ function getStaticAPIRoutes(): RouteDefinition[] { const appPathsStaticAPIRoutes = Object.values(AppPathRoutesManifest) .filter( (route) => - route.startsWith("/api/") || - (route === "/api" && !dynamicRoutePages.has(route)), + (route.startsWith("/api/") || route === "/api") && + !dynamicRoutePages.has(route), ) .map(createRouteDefinition); From 150fea00bdd4c4bfd09419feec2dbe7165065267 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Fri, 10 Oct 2025 13:44:04 +0200 Subject: [PATCH 2/4] changeset --- .changeset/fluffy-penguins-doubt.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fluffy-penguins-doubt.md diff --git a/.changeset/fluffy-penguins-doubt.md b/.changeset/fluffy-penguins-doubt.md new file mode 100644 index 000000000..930a9b1fe --- /dev/null +++ b/.changeset/fluffy-penguins-doubt.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +fix: Ensure dynamic routes are excluded in getStaticAPIRoutes From 6d8d62801c3ab030e2a2e9838f1246eefdf88cb3 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Fri, 10 Oct 2025 15:37:33 +0200 Subject: [PATCH 3/4] e2e --- .../app/api/auth/[...better-auth]/route.ts | 12 ++++++++++++ .../tests/appRouter/dynamic.catch-all.hypen.test.ts | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 examples/app-router/app/api/auth/[...better-auth]/route.ts create mode 100644 packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts diff --git a/examples/app-router/app/api/auth/[...better-auth]/route.ts b/examples/app-router/app/api/auth/[...better-auth]/route.ts new file mode 100644 index 000000000..74d5dceea --- /dev/null +++ b/examples/app-router/app/api/auth/[...better-auth]/route.ts @@ -0,0 +1,12 @@ +import { NextResponse } from "next/server"; + +export async function GET( + _req: Request, + { params }: { params: Promise<{ "better-auth": string[] }> }, +) { + const { "better-auth": slugs } = await params; + + return NextResponse.json({ + slugs, + }); +} diff --git a/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts b/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts new file mode 100644 index 000000000..c00dd698a --- /dev/null +++ b/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts @@ -0,0 +1,9 @@ +import { expect, test } from "@playwright/test"; + +test("Dynamic catch-all API route with hyphen param", async ({ request }) => { + const res = await request.get("/api/auth/opennext/is/really/cool"); + expect(res.status()).toBe(200); + expect(res.headers()["content-type"]).toBe("application/json"); + const json = await res.json(); + expect(json).toStrictEqual({ slugs: ["opennext", "is", "really", "cool"] }); +}); From d8d4aba14b5c807f5813b8284a1df9d8e851a347 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Fri, 10 Oct 2025 15:41:59 +0200 Subject: [PATCH 4/4] add issue in comment --- .../tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts b/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts index c00dd698a..27c911af8 100644 --- a/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts +++ b/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "@playwright/test"; +// https://github.com/opennextjs/opennextjs-cloudflare/issues/942 test("Dynamic catch-all API route with hyphen param", async ({ request }) => { const res = await request.get("/api/auth/opennext/is/really/cool"); expect(res.status()).toBe(200);