@increase21/simplenodejs 2.0.0 → 2.0.1

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 +3 -4
  2. package/package.json +1 -1
package/dist/router.js CHANGED
@@ -48,9 +48,8 @@ async function route(req, res) {
48
48
  }
49
49
  }
50
50
  //checking if the method does not require id but id is provided, if so, return 404
51
- if (id.length && (!controller[methodName].length || controller[methodName].length === 1)) {
51
+ if (id.length && !controller[methodName].length)
52
52
  return (0, helpers_1.throwHttpError)(404, "Resource not found");
53
- }
54
53
  //also add the context to the controller instance so that it can be accessed in the methods without passing it as a parameter
55
54
  controller.ctx = ctx;
56
55
  const descriptors = await controller[methodName](ctx, ...id);
@@ -61,7 +60,7 @@ async function route(req, res) {
61
60
  if (!descriptors || !Array.isArray(descriptors))
62
61
  return res.end();
63
62
  // Find the descriptor matching the HTTP method
64
- const descriptor = descriptors.find((d) => d.method === httpMethod);
63
+ const descriptor = descriptors.find(d => d.method === httpMethod);
65
64
  if (!descriptor)
66
65
  return (0, helpers_1.throwHttpError)(405, "Method Not Allowed");
67
66
  // Id validation
@@ -70,7 +69,7 @@ async function route(req, res) {
70
69
  if (descriptor.id === "required" && !id.length)
71
70
  return (0, helpers_1.throwHttpError)(404, "Resource not found");
72
71
  // Run endpoint-level middlewares before the handler
73
- if (descriptor.middleware?.length) {
72
+ if (descriptor.middleware && descriptor.middleware.length) {
74
73
  await (0, helpers_1.composeMiddleware)(descriptor.middleware)(req, res);
75
74
  }
76
75
  // If the handler has already sent a response, do not proceed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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",