Skip to content

Commit 8dd43ee

Browse files
authored
fix: Ensure dynamic routes are excluded in getStaticAPIRoutes (#1001)
1 parent d07c9f1 commit 8dd43ee

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix: Ensure dynamic routes are excluded in getStaticAPIRoutes
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NextResponse } from "next/server";
2+
3+
export async function GET(
4+
_req: Request,
5+
{ params }: { params: Promise<{ "better-auth": string[] }> },
6+
) {
7+
const { "better-auth": slugs } = await params;
8+
9+
return NextResponse.json({
10+
slugs,
11+
});
12+
}

packages/open-next/src/core/routing/routeMatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function getStaticAPIRoutes(): RouteDefinition[] {
8686
const appPathsStaticAPIRoutes = Object.values(AppPathRoutesManifest)
8787
.filter(
8888
(route) =>
89-
route.startsWith("/api/") ||
90-
(route === "/api" && !dynamicRoutePages.has(route)),
89+
(route.startsWith("/api/") || route === "/api") &&
90+
!dynamicRoutePages.has(route),
9191
)
9292
.map(createRouteDefinition);
9393

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
// https://github.com/opennextjs/opennextjs-cloudflare/issues/942
4+
test("Dynamic catch-all API route with hyphen param", async ({ request }) => {
5+
const res = await request.get("/api/auth/opennext/is/really/cool");
6+
expect(res.status()).toBe(200);
7+
expect(res.headers()["content-type"]).toBe("application/json");
8+
const json = await res.json();
9+
expect(json).toStrictEqual({ slugs: ["opennext", "is", "really", "cool"] });
10+
});

0 commit comments

Comments
 (0)