fix: rest api with Next.js basePath option (#10535)
Fixes https://github.com/payloadcms/payload/issues/10534
This commit is contained in:
@@ -26,6 +26,7 @@ const handlerBuilder =
|
||||
initedOGEndpoint = true
|
||||
|
||||
const response = await handleEndpoints({
|
||||
basePath: process.env.NEXT_BASE_PATH,
|
||||
config,
|
||||
request,
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user