@increase21/simplenodejs 2.0.0 → 2.0.2
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 +4 -5
- package/package.json +1 -1
package/dist/router.js
CHANGED
|
@@ -48,12 +48,11 @@ 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 &&
|
|
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
|
-
const descriptors = await controller[methodName](
|
|
55
|
+
const descriptors = await controller[methodName](...id);
|
|
57
56
|
// If the controller method has already sent a response, do not proceed
|
|
58
57
|
if (res.writableEnded)
|
|
59
58
|
return;
|
|
@@ -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(
|
|
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
|
|
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