/** * Copyright 2023 Kapeta Inc. * SPDX-License-Identifier: BUSL-1.1 */ import { NextFunction, Request, Response } from 'express'; export type StringBodyRequest = Request & { stringBody?: string; }; export function stringBody(req: StringBodyRequest, res: Response, next: NextFunction) { // push the data to body const body: Buffer[] = []; req.on('data', (chunk) => { body.push(chunk); }).on('end', () => { req.body = Buffer.concat(body); req.stringBody = req.body.toString(); next(); }); }