cpeak 1.0.0 → 1.1.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,6 +1,7 @@
1
1
  const http = require("node:http");
2
2
  const fs = require("node:fs/promises");
3
3
 
4
+ const { parseJSON } = require("./util");
4
5
  class CPeak {
5
6
  constructor() {
6
7
  this.server = http.createServer();
@@ -69,4 +70,6 @@ class CPeak {
69
70
  }
70
71
  }
71
72
 
73
+ CPeak.parseJSON = parseJSON;
74
+
72
75
  module.exports = CPeak;
package/lib/util.js ADDED
@@ -0,0 +1,18 @@
1
+ // Parsing JSON
2
+ exports.parseJSON = (req, res, next) => {
3
+ // This is only good for bodies that their size is less than the highWaterMark value
4
+ if (req.headers["content-type"] === "application/json") {
5
+ let body = "";
6
+ req.on("data", (chunk) => {
7
+ body += chunk.toString("utf-8");
8
+ });
9
+
10
+ req.on("end", () => {
11
+ body = JSON.parse(body);
12
+ req.body = body;
13
+ return next();
14
+ });
15
+ } else {
16
+ next();
17
+ }
18
+ };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "cpeak",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "./lib/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },