【发布时间】:2022-02-08 06:14:37
【问题描述】:
我需要获取原始正文请求以生成签名。 当我找到解决方案时,我遇到了 json 函数不起作用的问题 下面的例子:
import { Injectable, NestMiddleware } from '@nestjs/common';
import { json } from 'body-parser';
import { IncomingMessage } from 'http';
@Injectable()
export class RawBodyMiddlewareMiddleware implements NestMiddleware {
public use(req: IncomingMessage, res, next: () => any): any {
json({ //json function not fired
verify: (req, res, buffer) => {
console.log(buffer);
if (Buffer.isBuffer(buffer)) {
const rawBody = Buffer.from(buffer);
req['parsedRawBody'] = rawBody;
}
return true;
},
})(req, res as any, next);
}
}
【问题讨论】:
标签: nestjs body-parser