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 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/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); 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..27c911af8 --- /dev/null +++ b/packages/tests-e2e/tests/appRouter/dynamic.catch-all.hypen.test.ts @@ -0,0 +1,10 @@ +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); + expect(res.headers()["content-type"]).toBe("application/json"); + const json = await res.json(); + expect(json).toStrictEqual({ slugs: ["opennext", "is", "really", "cool"] }); +});