Skip to content

Commit

Permalink
fix: fix basePath support for API routes
Browse files Browse the repository at this point in the history
Fixes: #522
  • Loading branch information
socsieng committed Sep 23, 2024
1 parent 388b4e7 commit 7fad04d
Showing 1 changed file with 7 additions and 2 deletions.
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 7fad04d

Please sign in to comment.