44 RawServerBase ,
55 FastifyPluginAsync ,
66 RouteGenericInterface ,
7- RawReplyDefaultExpression ,
87} from "fastify" ;
98import { FastifyRequest , RequestGenericInterface } from "fastify/types/request" ;
109import proxy , { type FastifyHttpProxyOptions } from "@fastify/http-proxy" ;
@@ -17,6 +16,7 @@ import { extractDomElements } from "./lib/extractDomElements";
1716import { Http2ServerRequest } from "http2" ;
1817import { text } from "node:stream/consumers" ;
1918import { parse as parseContentType } from "fast-content-type-parse" ;
19+ import { IncomingMessage } from "http" ;
2020
2121type RenderedPageContext = Awaited <
2222 ReturnType <
@@ -62,7 +62,11 @@ interface ViteProxyPluginOptions extends Omit<
6262 ) => Promise < Partial < Omit < PageContextServer , "headers" > > > ;
6363 beforeWrappedRender ?: (
6464 req : FastifyRequest < RequestGenericInterface , RawServerBase > ,
65- res : RawReplyDefaultExpression < RawServerBase >
65+ reply : FastifyReply <
66+ RouteGenericInterface ,
67+ RawServerBase ,
68+ IncomingMessage | Http2ServerRequest
69+ >
6670 ) => void ;
6771}
6872/**
@@ -250,7 +254,13 @@ export const viteProxyPlugin: FastifyPluginAsync<
250254 return reply . send ( html ) ;
251255 }
252256
253- beforeWrappedRender ?.( req , res ) ;
257+ try {
258+ beforeWrappedRender ?.( req , reply ) ;
259+ } catch ( e ) {
260+ req . log . error (
261+ `Error in beforeWrappedRender: ${ ( e as Error ) . message } `
262+ ) ;
263+ }
254264
255265 const pageContextInit = {
256266 urlOriginal : reply . request . url ,
0 commit comments