@increase21/simplenodejs 1.0.16 → 1.0.17
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.d.ts +1 -1
- package/dist/router.js +5 -4
- package/dist/utils/helpers.js +0 -1
- package/package.json +1 -1
package/dist/router.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { RequestObject, ResponseObject } from "./typings/general";
|
|
|
2
2
|
import { SimpleJsControllerMeta } from "./typings/simpletypes";
|
|
3
3
|
export declare function loadControllers(root?: string): Map<string, SimpleJsControllerMeta>;
|
|
4
4
|
export declare function setControllersDir(dir: string): void;
|
|
5
|
-
export declare function route(req: RequestObject, res: ResponseObject
|
|
5
|
+
export declare function route(req: RequestObject, res: ResponseObject): Promise<void>;
|
package/dist/router.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.route = route;
|
|
|
9
9
|
// router.ts
|
|
10
10
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const helpers_1 = require("./utils/helpers");
|
|
12
13
|
let controllers = new Map();
|
|
13
14
|
function loadControllers(root = "controllers") {
|
|
14
15
|
const base = node_path_1.default.resolve(process.cwd(), root);
|
|
@@ -42,7 +43,7 @@ function loadControllers(root = "controllers") {
|
|
|
42
43
|
function setControllersDir(dir) {
|
|
43
44
|
controllers = loadControllers(dir);
|
|
44
45
|
}
|
|
45
|
-
async function route(req, res
|
|
46
|
+
async function route(req, res) {
|
|
46
47
|
let parts = req._end_point_path || [];
|
|
47
48
|
let controllerPath = (parts.length > 2 ? "/" + parts.slice(0, 2).join("/") : `/${parts.join("/")}`).toLocaleLowerCase();
|
|
48
49
|
let methodName = parts.length > 2 ? parts[2] : "index";
|
|
@@ -50,7 +51,7 @@ async function route(req, res, controllersDir) {
|
|
|
50
51
|
const meta = controllers.get(controllerPath);
|
|
51
52
|
//if the controller is not available or not found
|
|
52
53
|
if (!meta || !meta.name || !meta.Controller)
|
|
53
|
-
return
|
|
54
|
+
return (0, helpers_1.throwHttpError)(404, "The requested resource does not exist");
|
|
54
55
|
const ControllerClass = meta.Controller;
|
|
55
56
|
const controller = new ControllerClass();
|
|
56
57
|
//Update the method name to the framework pathen
|
|
@@ -63,12 +64,12 @@ async function route(req, res, controllersDir) {
|
|
|
63
64
|
id = parts.slice(2);
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
|
-
return
|
|
67
|
+
return (0, helpers_1.throwHttpError)(404, "The requested resource does not exist");
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
//if the data require params but there's no matching params
|
|
70
71
|
if (id && id.length && (!controller[methodName].length || controller[methodName].length < id.length)) {
|
|
71
|
-
return
|
|
72
|
+
return (0, helpers_1.throwHttpError)(404, "The requested resource does not exist");
|
|
72
73
|
}
|
|
73
74
|
//bind the controller to use the global properties
|
|
74
75
|
controller.__bindContext({ req, res });
|
package/dist/utils/helpers.js
CHANGED
package/package.json
CHANGED