From 126b353b694adcd9c7801c0ede46360a72c9b725 Mon Sep 17 00:00:00 2001 From: Master Date: Mon, 29 May 2023 07:01:40 +0800 Subject: [PATCH] fix body json+token --- src/middleware/middleware.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/middleware/middleware.ts b/src/middleware/middleware.ts index 1653864a..e9d0f103 100644 --- a/src/middleware/middleware.ts +++ b/src/middleware/middleware.ts @@ -8,7 +8,17 @@ const unknownEndpointHandler = (request: Request, response: Response) => { const requestLogger = (request: Request, _response: Response, next: NextFunction) => { console.log("Method:", request.method); console.log("Path: ", request.path); - console.log("Body: ", request.body); + if (Buffer.isBuffer(request.body)) { + const str = request.body.toString(); + const index = str.lastIndexOf("}"); + const jsonSubstring = str.substring(0, index + 1); + console.log("Body: ", jsonSubstring); + request.body = jsonSubstring; + if (str.length > jsonSubstring.length) { + const token = str.substring(index + 1, str.length).trim(); + console.log("Token: ", token); + } + } console.log("---"); next(); };