@bee.js/node 0.0.59 → 0.0.61
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/lib/beeHive/routes.js +32 -29
- package/package.json +1 -1
package/lib/beeHive/routes.js
CHANGED
|
@@ -1,35 +1,38 @@
|
|
|
1
|
-
const express
|
|
2
|
-
const log
|
|
3
|
-
const route
|
|
4
|
-
const freeRoute = require(
|
|
1
|
+
const express = require("express");
|
|
2
|
+
const log = require("./log");
|
|
3
|
+
const route = require("../WEB/route");
|
|
4
|
+
const freeRoute = require("../WEB/freeRoute");
|
|
5
5
|
|
|
6
|
-
module.exports = function() {
|
|
7
|
-
|
|
6
|
+
module.exports = function () {
|
|
7
|
+
if (!global.routes) return;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const controllers = global.controllers
|
|
9
|
+
const router = express.Router();
|
|
10
|
+
const controllers = global.controllers;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, controllers
|
|
27
|
-
)
|
|
12
|
+
global.routes?.map((r) => {
|
|
13
|
+
let controller =
|
|
14
|
+
typeof r.controller !== "string"
|
|
15
|
+
? r.controller
|
|
16
|
+
: r.controller.split(".").reduce((obj, i) => {
|
|
17
|
+
return obj && obj[i]
|
|
18
|
+
? obj[i]
|
|
19
|
+
: (log(
|
|
20
|
+
`The controller '${i}' is not found in '${r.controller}'`,
|
|
21
|
+
1
|
|
22
|
+
),
|
|
23
|
+
() => null);
|
|
24
|
+
}, controllers);
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
!router[r.method || "get"]
|
|
27
|
+
? console.log(`ERROR: method not found`, r)
|
|
28
|
+
: router[r.method || "get"](
|
|
29
|
+
r.route,
|
|
30
|
+
r.free ? freeRoute : route,
|
|
31
|
+
controller
|
|
32
|
+
);
|
|
33
|
+
});
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
log(`${Object.keys(global.routes).length} route(s)`);
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
}
|
|
37
|
+
return router;
|
|
38
|
+
};
|