@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 CHANGED
@@ -43,9 +43,7 @@ function setControllersDir(dir) {
43
43
  controllers = loadControllers(dir);
44
44
  }
45
45
  async function route(req, res, controllersDir) {
46
- // console.log("Router is called")
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
  };
@@ -17,6 +17,7 @@ export interface RequestObject extends IncomingMessage {
17
17
  body?: any;
18
18
  query?: any;
19
19
  id?: string;
20
+ _end_point_path?: string[];
20
21
  _server_environment?: 'dev' | 'stag' | 'live';
21
22
  _custom_data?: ObjectPayload;
22
23
  }
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Lightweight Node.js HTTP framework with middleware and plugins",
5
5
  "dev": "dist/index.js",
6
6
  "bugs": "https://github.com/increase21/simplenodejs/issues",