fix: rest api with Next.js basePath option (#10535)

Fixes https://github.com/payloadcms/payload/issues/10534
This commit is contained in:
Sasha
2025-01-13 11:37:50 +02:00
committed by GitHub
parent ab564d3731
commit 04a8083658
2 changed files with 4 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ const handlerBuilder =
initedOGEndpoint = true
const response = await handleEndpoints({
basePath: process.env.NEXT_BASE_PATH,
config,
request,
})

View File

@@ -58,9 +58,11 @@ const notFoundResponse = (req: PayloadRequest) => {
* ```
*/
export const handleEndpoints = async ({
basePath = '',
config: incomingConfig,
request,
}: {
basePath?: string
config: Promise<SanitizedConfig> | SanitizedConfig
request: Request
}): Promise<Response> => {
@@ -112,7 +114,7 @@ export const handleEndpoints = async ({
const { payload } = req
const { config } = payload
const pathname = new URL(req.url).pathname
const pathname = `${basePath}${new URL(req.url).pathname}`
if (!pathname.startsWith(config.routes.api)) {
return notFoundResponse(req)