I've had a problem with middleware function which is launching on finish execution of main function from endpoint. Here is my middleware:
export const someMiddleware = async (
req: Request,
res: Response,
next: NextFunction
) => {
res.on("finish", () => {
//here
})
next();
}
I am having trouble getting the data that was sent to the client from the request handled by this middleware, can anyone tell me how to get the response body that is sent to the client inside the on () callback?
Thanks for any help!
This is quite painful with Express. One way to handle this is to override the send and write functions, and capture the output this way.
It's not impossible to do this, other middlewares like a gzip middleware would do this too.
A frustration with this limitation has eventually lead me to write my own framework, so I get where you are coming from.