@@ -87,7 +87,12 @@ export async function serverResponse(req: Request, body: string) {
87
87
88
88
const routeParams = extractDynamicSegments ( foundRoute . uri , url . pathname )
89
89
90
- await addRouteQuery ( url , body )
90
+ if ( ! body ) {
91
+ await addRouteQuery ( url )
92
+ } else {
93
+ await addBody ( body )
94
+ }
95
+
91
96
await addRouteParam ( routeParams )
92
97
await addHeaders ( req . headers )
93
98
@@ -214,7 +219,9 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
214
219
215
220
if ( isObject ( foundCallback ) && foundCallback . status ) {
216
221
if ( foundCallback . status === 422 ) {
222
+ // biome-ignore lint/performance/noDelete: <explanation>
217
223
delete foundCallback . status
224
+
218
225
return await new Response ( JSON . stringify ( foundCallback ) , {
219
226
headers : {
220
227
'Content-Type' : 'json' ,
@@ -229,6 +236,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
229
236
if ( isObject ( foundCallback ) && foundCallback . status ) {
230
237
if ( foundCallback . status === 401 ) {
231
238
delete foundCallback . status
239
+
232
240
return await new Response ( JSON . stringify ( foundCallback ) , {
233
241
headers : {
234
242
'Content-Type' : 'json' ,
@@ -283,7 +291,7 @@ function noCache(response: Response) {
283
291
return response
284
292
}
285
293
286
- async function addRouteQuery ( url : URL , body : string ) {
294
+ async function addRouteQuery ( url : URL ) {
287
295
const modelFiles = glob . sync ( path . userModelsPath ( '*.ts' ) )
288
296
289
297
for ( const modelFile of modelFiles ) {
@@ -294,14 +302,31 @@ async function addRouteQuery(url: URL, body: string) {
294
302
const requestImport = await import ( requestPath )
295
303
const requestInstance = requestImport [ modelNameLower ]
296
304
297
- if ( requestInstance && ! isObjectNotEmpty ( url . searchParams ) ) {
298
- requestInstance . addQuery ( url , JSON . parse ( body ) )
305
+ if ( requestInstance ) {
306
+ requestInstance . addQuery ( url )
299
307
}
300
308
}
301
309
302
- if ( ! isObjectNotEmpty ( url . searchParams ) ) {
303
- RequestParam . addQuery ( url , JSON . parse ( body ) )
310
+ RequestParam . addQuery ( url )
311
+ }
312
+
313
+ async function addBody ( params : any ) {
314
+ const modelFiles = glob . sync ( path . userModelsPath ( '*.ts' ) )
315
+
316
+ for ( const modelFile of modelFiles ) {
317
+ const model = ( await import ( modelFile ) ) . default
318
+ const modelName = getModelName ( model , modelFile )
319
+ const modelNameLower = `${ camelCase ( modelName ) } Request`
320
+ const requestPath = path . projectStoragePath ( `framework/requests/${ modelName } Request.ts` )
321
+ const requestImport = await import ( requestPath )
322
+ const requestInstance = requestImport [ modelNameLower ]
323
+
324
+ if ( requestInstance ) {
325
+ requestInstance . addBodies ( JSON . parse ( params ) )
326
+ }
304
327
}
328
+
329
+ RequestParam . addBodies ( JSON . parse ( params ) )
305
330
}
306
331
307
332
async function addRouteParam ( param : RouteParam ) : Promise < void > {
0 commit comments