@increase21/simplenodejs 1.0.22 → 1.0.24

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.
package/dist/router.js CHANGED
@@ -16,7 +16,7 @@ async function route(req, res) {
16
16
  let parts = req._end_point_path || [];
17
17
  let controllerPath = (parts.length > 2 ? "/" + parts.slice(0, 2).join("/") : `/${parts.join("/")}`).toLowerCase().replace(/\-{1}\w{1}/g, match => match.replace("-", "").toUpperCase());
18
18
  let methodName = parts.length > 2 ? parts[2] : "index";
19
- let id = methodName !== "index" ? parts.slice(3).join("/") : null;
19
+ let id = methodName !== "index" ? parts.slice(3) : [];
20
20
  let httpMethod = (req.method || "").toLowerCase();
21
21
  const meta = controllers.get(controllerPath);
22
22
  //if the controller is not available or not found
@@ -34,7 +34,7 @@ async function route(req, res) {
34
34
  if (typeof controller[methodName] !== "function") {
35
35
  if (typeof controller["index"] === "function" && parts.length === 3) {
36
36
  methodName = "index";
37
- id = parts.slice(2).join("/"); // pass the rest of the path as ID;
37
+ id = parts.slice(2) || []; // pass the rest of the path as ID;
38
38
  }
39
39
  else {
40
40
  return (0, helpers_1.throwHttpError)(404, "The requested resource does not exist");
@@ -46,7 +46,7 @@ async function route(req, res) {
46
46
  }
47
47
  //bind the controller to use the global properties
48
48
  controller.__bindContext({ req, res });
49
- let result = await controller[methodName](id);
49
+ let result = await controller[methodName](...id);
50
50
  //if the cycle has ended
51
51
  if (res.writableEnded)
52
52
  return;
@@ -57,13 +57,13 @@ async function route(req, res) {
57
57
  if (result && typeof result[httpMethod] !== "function")
58
58
  return (0, helpers_1.throwHttpError)(405, "Method Not Allowed");
59
59
  // ID validation rules
60
- if (id && (!result.id || !result.id[httpMethod]))
60
+ if (id.length && (!result.id || !result.id[httpMethod]))
61
61
  return (0, helpers_1.throwHttpError)(404, "Resource not found");
62
- if (result.id && result.id[httpMethod] === "required" && !id)
62
+ if (result.id && result.id[httpMethod] === "required" && !id.length)
63
63
  return (0, helpers_1.throwHttpError)(404, "Resource not found");
64
64
  result = await result[httpMethod]({
65
65
  req, res, query: controller.query, body: controller.body,
66
- id: id, customData: controller._custom_data
66
+ id: id.join("/"), customData: controller._custom_data
67
67
  });
68
68
  //if not responded
69
69
  if (!res.writableEnded)
@@ -189,7 +189,7 @@ function SetBodyParser(opts) {
189
189
  const isMultipart = contentType.includes("multipart/form-data");
190
190
  let size = 0;
191
191
  let body = "";
192
- req.on("data", chunk => {
192
+ !isMultipart && req.on("data", chunk => {
193
193
  size += chunk.length;
194
194
  if (maxSize && size > maxSize) {
195
195
  reject({ code: 413, error: "Payload Too Large" });
@@ -199,8 +199,7 @@ function SetBodyParser(opts) {
199
199
  req.socket.destroy();
200
200
  return;
201
201
  }
202
- if (!isMultipart)
203
- body += chunk;
202
+ body += chunk;
204
203
  });
205
204
  req.on("end", () => {
206
205
  if (res.writableEnded)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Lightweight Node.js HTTP framework with middlewares and plugins",
5
5
  "dev": "dist/index.js",
6
6
  "bugs": "https://github.com/increase21/simplenodejs/issues",