@@ -757,17 +757,51 @@ export async function startEventServer(opts: {
757
757
}
758
758
759
759
const bodyLimit = 1_000_000 * 500 ; // 500MB body limit
760
+
761
+ const reqLogSerializer = ( req : FastifyRequest ) => ( {
762
+ method : req . method ,
763
+ url : req . url ,
764
+ version : req . headers ?. [ 'accept-version' ] as string ,
765
+ hostname : req . hostname ,
766
+ remoteAddress : req . ip ,
767
+ remotePort : req . socket ?. remotePort ,
768
+ bodySize : parseInt ( req . headers ?. [ 'content-length' ] as string ) || 'unknown' ,
769
+ } ) ;
770
+
760
771
const loggerOpts : FastifyServerOptions [ 'logger' ] = {
761
772
...PINO_LOGGER_CONFIG ,
762
773
name : 'stacks-node-event' ,
774
+ serializers : {
775
+ req : reqLogSerializer ,
776
+ res : reply => ( {
777
+ statusCode : reply . statusCode ,
778
+ method : reply . request ?. method ,
779
+ url : reply . request ?. url ,
780
+ requestBodySize : parseInt ( reply . request ?. headers [ 'content-length' ] as string ) || 'unknown' ,
781
+ responseBodySize : parseInt ( reply . getHeader ?.( 'content-length' ) as string ) || 'unknown' ,
782
+ } ) ,
783
+ } ,
763
784
} ;
785
+
764
786
const app = Fastify ( {
765
787
bodyLimit,
766
788
trustProxy : true ,
767
789
logger : loggerOpts ,
768
790
ignoreTrailingSlash : true ,
769
791
} ) ;
770
792
793
+ app . addHook ( 'onRequest' , ( req , reply , done ) => {
794
+ req . raw . on ( 'close' , ( ) => {
795
+ if ( req . raw . aborted ) {
796
+ req . log . warn (
797
+ reqLogSerializer ( req ) ,
798
+ `Request was aborted by the client: ${ req . method } ${ req . url } `
799
+ ) ;
800
+ }
801
+ } ) ;
802
+ done ( ) ;
803
+ } ) ;
804
+
771
805
const handleRawEventRequest = async ( req : FastifyRequest ) => {
772
806
await messageHandler . handleRawEventRequest ( req . url , req . body , db ) ;
773
807
0 commit comments