Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-news-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix: fix basePath support for API routes
9 changes: 7 additions & 2 deletions packages/open-next/src/core/routingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const optionalBasepathPrefixRegex = !!RoutesManifest.basePath
? `^${RoutesManifest.basePath}/?`
: "^/";

// Add the basePath prefix to the api routes
const apiPrefix = !!RoutesManifest.basePath
? `${RoutesManifest.basePath}/api`
: "/api";

const staticRegexp = RoutesManifest.routes.static.map(
(route) =>
new RegExp(
Expand Down Expand Up @@ -145,8 +150,8 @@ export default async function routingHandler(
// /api even if it's a page route doesn't get generated in the manifest
// Ideally we would need to properly check api routes here
const isApiRoute =
internalEvent.rawPath === "/api" ||
internalEvent.rawPath.startsWith("/api/");
internalEvent.rawPath === apiPrefix ||
internalEvent.rawPath.startsWith(`${apiPrefix}/`);

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

Expand Down
Loading