@increase21/simplenodejs 1.0.21 → 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.
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)
|
|
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)
|
|
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)
|
|
@@ -23,7 +23,7 @@ function normalizeIP(raw) {
|
|
|
23
23
|
}
|
|
24
24
|
// ─── Security Plugin ──────────────────────────────────────────────────────────
|
|
25
25
|
function SimpleJsSecurityPlugin(app, opts) {
|
|
26
|
-
if (opts.cors
|
|
26
|
+
if (opts.cors)
|
|
27
27
|
app.use((0, simpleMiddleware_1.SetCORS)(opts.cors));
|
|
28
28
|
if (opts.helmet)
|
|
29
29
|
app.use((0, simpleMiddleware_1.SetHelmet)(opts.helmet === true ? undefined : opts.helmet));
|
package/package.json
CHANGED