Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import { NextFunction, Request, Response } from "express"
export function ParseBodyMiddleware(req: Request & { rawBody?: string }, _res: Response, next: NextFunction) {
const chunks: Buffer[] = []
req.on("data", (chunk) => {
chunks.push(chunk)
})
req.on("end", () => {
const buffer = Buffer.concat(chunks)
req.rawBody = buffer.toString("utf8")
req.body = JSON.parse(req.rawBody || "{}")
next()
})
}
|