@bee.js/node 0.0.102 → 0.0.104

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.
@@ -4,12 +4,17 @@ const freeRoute = require("../WEB/freeRoute");
4
4
  const log = require("./log");
5
5
  const headers = require("./headers");
6
6
  const bodyParser = require("body-parser");
7
+ const createBodyParsers = require("./utils/bodyParsers");
7
8
 
8
9
  module.exports = function () {
9
10
  if (!global.routes) return;
10
11
 
11
12
  const router = express.Router();
12
13
  const controllers = global.controllers;
14
+ const bodyParsers = createBodyParsers(bodyParser);
15
+
16
+ router.use(...bodyParsers);
17
+ router.use((req, res, next) => headers({ req, res, next, router, configs }));
13
18
 
14
19
  global.routes?.forEach((r) => {
15
20
  let controller =
@@ -35,18 +40,6 @@ module.exports = function () {
35
40
  },
36
41
  controller
37
42
  );
38
-
39
- router.use(
40
- bodyParser.urlencoded({
41
- limit: "20mb",
42
- extended: true,
43
- parameterLimit: 50000,
44
- })
45
- );
46
-
47
- router.use(bodyParser.json({ extended: true, limit: "20mb" }));
48
- router.use(bodyParser.raw());
49
- router.use((req, res, next) => headers({ req, res, next, router, configs }));
50
43
  });
51
44
 
52
45
  log(`${Object.keys(global.routes).length} route(s) 222222
@@ -1,6 +1,7 @@
1
1
  const log = require("./log");
2
2
  const beeDEV = require("../DEV/beeDEV");
3
3
  const bodyParser = require('body-parser');
4
+ const createBodyParsers = require("./utils/bodyParsers");
4
5
  const http = require("http");
5
6
  const https = require("https");
6
7
  const fs = require("fs");
@@ -10,7 +11,11 @@ const servers = { http: null, https: null };
10
11
 
11
12
  module.exports = function (app, options = {}) {
12
13
  if (process.argv.includes("--dev"))
13
- app.post("/beedev/:action", bodyParser.json(), beeDEV);
14
+ app.post(
15
+ "/beedev/:action",
16
+ ...createBodyParsers(bodyParser),
17
+ beeDEV
18
+ );
14
19
 
15
20
  const ports = (global.configs.port || global.configs.ports || 1987.443)
16
21
  .toString()
@@ -0,0 +1,20 @@
1
+ const BODY_LIMIT = "100mb";
2
+ const URLENCODED_PARSER_OPTIONS = {
3
+ limit: BODY_LIMIT,
4
+ extended: true,
5
+ parameterLimit: 50000,
6
+ };
7
+ const JSON_PARSER_OPTIONS = {
8
+ limit: BODY_LIMIT,
9
+ };
10
+ const RAW_PARSER_OPTIONS = {
11
+ limit: BODY_LIMIT,
12
+ };
13
+
14
+ module.exports = function createBodyParsers(bodyParser) {
15
+ return [
16
+ bodyParser.urlencoded(URLENCODED_PARSER_OPTIONS),
17
+ bodyParser.json(JSON_PARSER_OPTIONS),
18
+ bodyParser.raw(RAW_PARSER_OPTIONS),
19
+ ];
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.102",
3
+ "version": "0.0.104",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/guid.js CHANGED
@@ -16,8 +16,19 @@ module.exports = {
16
16
 
17
17
  return "0x" + param.replace(/-/g, "");
18
18
  },
19
-
20
19
  uuidToBin: this.guidToBin,
21
20
 
21
+ binToGuid: function binToGuid(param) {
22
+ if (typeof param !== "string") return null;
23
+
24
+ const match = param.match(/^0x([0-9a-fA-F]{32})$/);
25
+ if (!match) return null;
26
+
27
+ const hex = match[1];
28
+
29
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
30
+ },
31
+ binToUuid: this.binToUuid,
32
+
22
33
  isUUID: str => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(str)
23
34
  };