Skip to content

Commit 5fc82a9

Browse files
authored
(#66) beforeWrappedRender call with reply instead of res
1 parent c39a3b3 commit 5fc82a9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

bifrost-fastify/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
RawServerBase,
55
FastifyPluginAsync,
66
RouteGenericInterface,
7-
RawReplyDefaultExpression,
87
} from "fastify";
98
import { FastifyRequest, RequestGenericInterface } from "fastify/types/request";
109
import proxy, { type FastifyHttpProxyOptions } from "@fastify/http-proxy";
@@ -17,6 +16,7 @@ import { extractDomElements } from "./lib/extractDomElements";
1716
import { Http2ServerRequest } from "http2";
1817
import { text } from "node:stream/consumers";
1918
import { parse as parseContentType } from "fast-content-type-parse";
19+
import { IncomingMessage } from "http";
2020

2121
type 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

Comments
 (0)