diff --git a/packages/open-next/src/core/routingHandler.ts b/packages/open-next/src/core/routingHandler.ts index 54936d66..1c4e7263 100644 --- a/packages/open-next/src/core/routingHandler.ts +++ b/packages/open-next/src/core/routingHandler.ts @@ -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( @@ -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");