Skip to content

Commit

Permalink
fix: fix basePath support for API routes (#523)
Browse files Browse the repository at this point in the history
* fix: fix basePath support for API routes

Fixes: #522

* Create polite-news-happen.md

---------

Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
  • Loading branch information
socsieng and conico974 authored Oct 3, 2024
1 parent 50703a3 commit 9fceedb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit 9fceedb

Please sign in to comment.