-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: attempt at caching only after response is sent
- Loading branch information
1 parent
55387a7
commit b2dd0eb
Showing
2 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { FastifyPluginAsync } from "fastify"; | ||
|
||
const plugin: FastifyPluginAsync = async (fastify): Promise<void> => { | ||
fastify.decorateReply("payloadData", null); | ||
|
||
fastify.addHook("onSend", function (req, reply, payload) { | ||
console.log("onSend:payloadData"); | ||
fastify.payloadData = payload; | ||
console.log("onSend:payloadData"); | ||
}); | ||
}; | ||
|
||
declare module "fastify" { | ||
export interface FastifyInstance { | ||
/** | ||
* `payload` is only populated after `onSend` hook | ||
* To be consumed inside `onRequest` hook | ||
*/ | ||
payloadData?: unknown; | ||
} | ||
} | ||
|
||
export default plugin; |