@@ -11,10 +11,10 @@ import { headersWithCors } from './headersWithCors.js'
11
11
import { mergeHeaders } from './mergeHeaders.js'
12
12
import { routeError } from './routeError.js'
13
13
14
- const notFoundResponse = ( req : PayloadRequest ) => {
14
+ const notFoundResponse = ( req : PayloadRequest , pathname ?: string ) => {
15
15
return Response . json (
16
16
{
17
- message : `Route not found "${ new URL ( req . url ) . pathname } "` ,
17
+ message : `Route not found "${ pathname ?? new URL ( req . url ) . pathname } "` ,
18
18
} ,
19
19
{
20
20
headers : headersWithCors ( {
@@ -61,10 +61,13 @@ const notFoundResponse = (req: PayloadRequest) => {
61
61
export const handleEndpoints = async ( {
62
62
basePath = '' ,
63
63
config : incomingConfig ,
64
+ path,
64
65
request,
65
66
} : {
66
67
basePath ?: string
67
68
config : Promise < SanitizedConfig > | SanitizedConfig
69
+ /** Override path from the request */
70
+ path ?: string
68
71
request : Request
69
72
} ) : Promise < Response > => {
70
73
let handler : PayloadHandler
@@ -85,6 +88,7 @@ export const handleEndpoints = async ({
85
88
const response = await handleEndpoints ( {
86
89
basePath,
87
90
config : incomingConfig ,
91
+ path,
88
92
request : new Request ( url , {
89
93
cache : request . cache ,
90
94
credentials : request . credentials ,
@@ -116,10 +120,10 @@ export const handleEndpoints = async ({
116
120
const { payload } = req
117
121
const { config } = payload
118
122
119
- const pathname = `${ basePath } ${ new URL ( req . url ) . pathname } `
123
+ const pathname = `${ basePath } ${ path ?? new URL ( req . url ) . pathname } `
120
124
121
125
if ( ! pathname . startsWith ( config . routes . api ) ) {
122
- return notFoundResponse ( req )
126
+ return notFoundResponse ( req , pathname )
123
127
}
124
128
125
129
// /api/posts/route -> /posts/route
@@ -213,7 +217,7 @@ export const handleEndpoints = async ({
213
217
}
214
218
215
219
if ( ! handler ) {
216
- return notFoundResponse ( req )
220
+ return notFoundResponse ( req , pathname )
217
221
}
218
222
219
223
const response = await handler ( req )
0 commit comments