Skip to content

Commit 9fceedb

Browse files
socsiengconico974
andauthored
fix: fix basePath support for API routes (#523)
* fix: fix basePath support for API routes Fixes: #522 * Create polite-news-happen.md --------- Co-authored-by: conico974 <[email protected]>
1 parent 50703a3 commit 9fceedb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/polite-news-happen.md

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: fix basePath support for API routes

packages/open-next/src/core/routingHandler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const optionalBasepathPrefixRegex = !!RoutesManifest.basePath
3434
? `^${RoutesManifest.basePath}/?`
3535
: "^/";
3636

37+
// Add the basePath prefix to the api routes
38+
const apiPrefix = !!RoutesManifest.basePath
39+
? `${RoutesManifest.basePath}/api`
40+
: "/api";
41+
3742
const staticRegexp = RoutesManifest.routes.static.map(
3843
(route) =>
3944
new RegExp(
@@ -145,8 +150,8 @@ export default async function routingHandler(
145150
// /api even if it's a page route doesn't get generated in the manifest
146151
// Ideally we would need to properly check api routes here
147152
const isApiRoute =
148-
internalEvent.rawPath === "/api" ||
149-
internalEvent.rawPath.startsWith("/api/");
153+
internalEvent.rawPath === apiPrefix ||
154+
internalEvent.rawPath.startsWith(`${apiPrefix}/`);
150155

151156
const isNextImageRoute = internalEvent.rawPath.startsWith("/_next/image");
152157

0 commit comments

Comments
 (0)