Skip to content

Commit

Permalink
fix: rest api with Next.js basePath option (#10535)
Browse files Browse the repository at this point in the history
Fixes #10534
  • Loading branch information
r1tsuu authored Jan 13, 2025
1 parent ab564d3 commit 04a8083
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/next/src/routes/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const handlerBuilder =
initedOGEndpoint = true

const response = await handleEndpoints({
basePath: process.env.NEXT_BASE_PATH,
config,
request,
})
Expand Down
4 changes: 3 additions & 1 deletion packages/payload/src/utilities/handleEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> => {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 04a8083

Please sign in to comment.