@@ -16,6 +16,7 @@ import { HandlerContract } from '../Contracts/Context/HandlerContract'
1616import { ErrorHandlerContract } from '../Contracts/Context/Error/ErrorHandlerContract'
1717import { HandleHandlerContract } from '../Contracts/Context/Middlewares/Handle/HandleHandlerContract'
1818import { InterceptHandlerContract } from '../Contracts/Context/Middlewares/Intercept/InterceptHandlerContract'
19+ import { Is } from '@secjs/utils'
1920
2021declare module 'fastify' {
2122 interface FastifyRequest {
@@ -33,7 +34,11 @@ export class FastifyHandler {
3334 if ( ! req . query ) req . query = { }
3435 if ( ! req . params ) req . params = { }
3536
36- const body = JSON . parse ( payload )
37+ let body = payload
38+
39+ if ( Is . Json ( payload ) ) {
40+ body = JSON . parse ( body )
41+ }
3742
3843 return handler ( {
3944 request,
@@ -42,7 +47,14 @@ export class FastifyHandler {
4247 params : req . params as Record < string , string > ,
4348 queries : req . query as Record < string , string > ,
4449 data : req . data ,
45- next : ( ) => done ( null , JSON . stringify ( body ) ) ,
50+ next : (
51+ body : string | Buffer | Record < string , any > | null ,
52+ error = null ,
53+ ) => {
54+ if ( Is . Object ( body ) ) body = JSON . stringify ( body )
55+
56+ done ( error , body )
57+ } ,
4658 } )
4759 }
4860 }
0 commit comments