@increase21/simplenodejs 1.0.22 → 1.0.23

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.
Files changed (2) hide show
  1. package/dist/router.js +6 -6
  2. package/package.json +1 -1
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
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",