@increase21/simplenodejs 1.0.9 → 1.0.11
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 +3 -3
- package/dist/server.js +5 -0
- package/dist/typings/general.d.ts +1 -0
- package/dist/utils/helpers.js +4 -4
- package/package.json +1 -1
package/dist/router.js
CHANGED
|
@@ -43,9 +43,7 @@ function setControllersDir(dir) {
|
|
|
43
43
|
controllers = loadControllers(dir);
|
|
44
44
|
}
|
|
45
45
|
async function route(req, res, controllersDir) {
|
|
46
|
-
|
|
47
|
-
const url = new URL(req.url, "http://localhost");
|
|
48
|
-
const parts = url.pathname.replace(/^\/+|\/+$/g, "").split("/");
|
|
46
|
+
let parts = req._end_point_path || [];
|
|
49
47
|
let controllerPath = (parts.length > 2 ? "/" + parts.slice(0, 2).join("/") : `/${parts.join("/")}`).toLocaleLowerCase();
|
|
50
48
|
let methodName = parts.length > 2 ? parts[2] : "index";
|
|
51
49
|
let id = methodName !== "index" ? parts.slice(parts.indexOf(methodName) + 1) : null;
|
|
@@ -55,6 +53,8 @@ async function route(req, res, controllersDir) {
|
|
|
55
53
|
return res.status(404).json({ error: "The requested resource does not exist" });
|
|
56
54
|
const ControllerClass = meta.Controller;
|
|
57
55
|
const controller = new ControllerClass();
|
|
56
|
+
//Update the method name to the framework pathen
|
|
57
|
+
methodName = (methodName || "").replace(/\-{1}\w{1}/g, match => match.replace("-", "").toUpperCase());
|
|
58
58
|
//if the endpoint not a function
|
|
59
59
|
if (typeof controller[methodName] !== "function") {
|
|
60
60
|
//if it's using index
|
package/dist/server.js
CHANGED
|
@@ -26,6 +26,11 @@ const extension = (req, res) => {
|
|
|
26
26
|
res.setHeader('Content-Type', 'text/plain');
|
|
27
27
|
res.end(param);
|
|
28
28
|
};
|
|
29
|
+
const url = new URL(req.url, "http://localhost");
|
|
30
|
+
req.query = url.search ? url.search.substring(1) : '';
|
|
31
|
+
//endpoint path
|
|
32
|
+
req._end_point_path = url.pathname.replace(/^\/+|\/+$/g, "").split("/");
|
|
33
|
+
//adding the request ID
|
|
29
34
|
req.id = node_crypto_1.default.randomUUID();
|
|
30
35
|
res.setHeader("X-Request-Id", req.id);
|
|
31
36
|
};
|
package/dist/utils/helpers.js
CHANGED
|
@@ -113,14 +113,14 @@ function SetBodyParser(opts) {
|
|
|
113
113
|
try {
|
|
114
114
|
if (body && !["application/text", "application/media"].includes(req.headers.accept)) {
|
|
115
115
|
req.body = JSON.parse(body);
|
|
116
|
-
//parse query
|
|
117
|
-
if (req.query) {
|
|
118
|
-
req.query = JSON.parse(JSON.stringify(node_querystring_1.default.parse(req.query)));
|
|
119
|
-
}
|
|
120
116
|
}
|
|
121
117
|
else {
|
|
122
118
|
req.body = body;
|
|
123
119
|
}
|
|
120
|
+
//parse query
|
|
121
|
+
if (req.query) {
|
|
122
|
+
req.query = JSON.parse(JSON.stringify(node_querystring_1.default.parse(req.query)));
|
|
123
|
+
}
|
|
124
124
|
resolve(next());
|
|
125
125
|
}
|
|
126
126
|
catch (e) {
|
package/package.json
CHANGED