@bee.js/node 0.0.91 → 0.0.92
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/create.js +2 -14
- package/lib/beeHive/headers.js +8 -15
- package/lib/beeHive/routes.js +21 -8
- package/package.json +1 -1
package/lib/beeHive/create.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
const express = require("express");
|
|
2
|
-
const bodyParser = require("body-parser");
|
|
3
2
|
const log = require("./log");
|
|
4
|
-
const headers = require("./headers");
|
|
5
3
|
|
|
6
4
|
module.exports = function (configs) {
|
|
7
5
|
const app = express();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
bodyParser.urlencoded({
|
|
11
|
-
limit: "10mb",
|
|
12
|
-
extended: true,
|
|
13
|
-
parameterLimit: 50000,
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
app.use(bodyParser.json({ extended: true, limit: "10mb" }));
|
|
17
|
-
app.use(bodyParser.raw());
|
|
18
|
-
app.use((req, res, next) => headers({ req, res, next, app, configs }));
|
|
19
|
-
|
|
6
|
+
app.express = express;
|
|
7
|
+
|
|
20
8
|
log(`Creating ${configs.name || "Bee.js"}...`);
|
|
21
9
|
log("Optimizing model(s)...");
|
|
22
10
|
|
package/lib/beeHive/headers.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
module.exports = function ({ next,
|
|
2
|
-
|
|
3
|
-
if (!configs.headers)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
res.header(
|
|
1
|
+
module.exports = function ({ next, router, configs = {} }) {
|
|
2
|
+
router.use((req, res) => {
|
|
3
|
+
if (!configs.headers) {
|
|
4
|
+
res.header("Access-Control-Allow-Origin", "*");
|
|
5
|
+
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS");
|
|
6
|
+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
// OPTIONS (preflight)
|
|
13
|
-
app.options("*", (req, res) => {
|
|
14
|
-
if (!configs.headers) res.header("Access-Control-Allow-Origin", "*");
|
|
9
|
+
if (req.method === "OPTIONS") return res.sendStatus(200);
|
|
15
10
|
|
|
16
11
|
for (const key in configs.headers || {}) {
|
|
17
12
|
res.header(key, configs.headers[key]);
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
return res.sendStatus(200);
|
|
21
14
|
});
|
|
22
15
|
|
|
23
16
|
next();
|
|
24
|
-
};
|
|
17
|
+
};
|
package/lib/beeHive/routes.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const express = require("express");
|
|
2
2
|
const log = require("./log");
|
|
3
3
|
const route = require("../WEB/route");
|
|
4
|
+
const bodyParser = require("body-parser");
|
|
5
|
+
const headers = require("./headers");
|
|
4
6
|
const freeRoute = require("../WEB/freeRoute");
|
|
5
7
|
|
|
6
8
|
module.exports = function () {
|
|
@@ -9,7 +11,7 @@ module.exports = function () {
|
|
|
9
11
|
const router = express.Router();
|
|
10
12
|
const controllers = global.controllers;
|
|
11
13
|
|
|
12
|
-
global.routes?.
|
|
14
|
+
global.routes?.forEach((r) => {
|
|
13
15
|
let controller =
|
|
14
16
|
typeof r.controller !== "string"
|
|
15
17
|
? r.controller
|
|
@@ -23,13 +25,24 @@ module.exports = function () {
|
|
|
23
25
|
() => null);
|
|
24
26
|
}, controllers);
|
|
25
27
|
|
|
26
|
-
!router[r.method || "get"]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (!router[r.method || "get"]) return console.log(`ERROR: method not found`, r);
|
|
29
|
+
|
|
30
|
+
router[r.method || "get"](
|
|
31
|
+
r.route,
|
|
32
|
+
r.free ? freeRoute : route,
|
|
33
|
+
controller
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
router.use(
|
|
37
|
+
bodyParser.urlencoded({
|
|
38
|
+
limit: "10mb",
|
|
39
|
+
extended: true,
|
|
40
|
+
parameterLimit: 50000,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
router.use(bodyParser.json({ extended: true, limit: "10mb" }));
|
|
44
|
+
router.use(bodyParser.raw());
|
|
45
|
+
router.use((req, res, next) => headers({ req, res, next, router, configs }));
|
|
33
46
|
});
|
|
34
47
|
|
|
35
48
|
log(`${Object.keys(global.routes).length} route(s)`);
|