cpeak 2.4.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +0,0 @@
1
- import type { CpeakRequest, CpeakResponse, Next } from "../types";
2
-
3
- // Parsing JSON
4
- const parseJSON = (req: CpeakRequest, res: CpeakResponse, next: Next) => {
5
- // This is only good for bodies that their size is less than the highWaterMark value
6
-
7
- function isJSON(contentType: string = "") {
8
- // Remove any params like "; charset=UTF-8"
9
- const [type] = contentType.split(";");
10
- return (
11
- type.trim().toLowerCase() === "application/json" ||
12
- /\+json$/i.test(type.trim())
13
- );
14
- }
15
-
16
- if (!isJSON(req.headers["content-type"] as string)) return next();
17
-
18
- let body = "";
19
- req.on("data", (chunk: Buffer) => {
20
- body += chunk.toString("utf-8");
21
- });
22
-
23
- req.on("end", () => {
24
- body = JSON.parse(body);
25
- req.body = body;
26
- return next();
27
- });
28
- };
29
-
30
- export { parseJSON };