@bee.js/node 0.0.91 → 0.0.93
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/DBA/beeDBA.js +4 -5
- package/lib/beeHive/create.js +2 -14
- package/lib/beeHive/headers.js +8 -15
- package/lib/beeHive/routes.js +25 -10
- package/lib/beeHive/start.js +4 -2
- package/package.json +4 -2
package/lib/DBA/beeDBA.js
CHANGED
|
@@ -54,14 +54,13 @@ module.exports.actions = {
|
|
|
54
54
|
},
|
|
55
55
|
|
|
56
56
|
MODEL_CREATE_DB: function (req, res) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const configsDB = global.configs.databases.default;
|
|
58
|
+
const models = global.models;
|
|
59
|
+
const SQL = ["", ""];
|
|
60
60
|
|
|
61
61
|
//TODO create db with user permissions
|
|
62
|
-
|
|
63
62
|
Object.keys(models).map((model) => {
|
|
64
|
-
if (!req.body
|
|
63
|
+
if (!req.body?.models?.[model]?._checked) return;
|
|
65
64
|
|
|
66
65
|
SQL[0] += this.MODEL_CREATE_TABLE(models[model], configsDB);
|
|
67
66
|
SQL[1] += models[model].relations
|
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,7 +1,9 @@
|
|
|
1
1
|
const express = require("express");
|
|
2
|
-
const log = require("./log");
|
|
3
2
|
const route = require("../WEB/route");
|
|
4
3
|
const freeRoute = require("../WEB/freeRoute");
|
|
4
|
+
const log = require("./log");
|
|
5
|
+
const headers = require("./headers");
|
|
6
|
+
const bodyParser = require("body-parser");
|
|
5
7
|
|
|
6
8
|
module.exports = function () {
|
|
7
9
|
if (!global.routes) return;
|
|
@@ -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,16 +25,29 @@ 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: "20mb",
|
|
39
|
+
extended: true,
|
|
40
|
+
parameterLimit: 50000,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
router.use(bodyParser.json({ extended: true, limit: "20mb" }));
|
|
45
|
+
router.use(bodyParser.raw());
|
|
46
|
+
router.use((req, res, next) => headers({ req, res, next, router, configs }));
|
|
33
47
|
});
|
|
34
48
|
|
|
35
|
-
log(`${Object.keys(global.routes).length} route(s)
|
|
49
|
+
log(`${Object.keys(global.routes).length} route(s) 222222
|
|
50
|
+
`);
|
|
36
51
|
|
|
37
52
|
return router;
|
|
38
53
|
};
|
package/lib/beeHive/start.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const log = require("./log");
|
|
2
2
|
const beeDEV = require("../DEV/beeDEV");
|
|
3
|
+
const bodyParser = require('body-parser');
|
|
3
4
|
const http = require("http");
|
|
4
5
|
const https = require("https");
|
|
5
6
|
const fs = require("fs");
|
|
@@ -8,12 +9,13 @@ const WebSocket = require("ws");
|
|
|
8
9
|
const servers = { http: null, https: null };
|
|
9
10
|
|
|
10
11
|
module.exports = function (app, options = {}) {
|
|
12
|
+
if (process.argv.includes("--dev"))
|
|
13
|
+
app.post("/beedev/:action", bodyParser.json(), beeDEV);
|
|
14
|
+
|
|
11
15
|
const ports = (global.configs.port || global.configs.ports || 1987.443)
|
|
12
16
|
.toString()
|
|
13
17
|
.split(".");
|
|
14
18
|
|
|
15
|
-
app.post("/beedev/:action", beeDEV); //TODO check security and create a method for define enable/disable
|
|
16
|
-
|
|
17
19
|
servers.http = http.createServer(app);
|
|
18
20
|
|
|
19
21
|
if (options.ws) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bee.js/node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.93",
|
|
4
4
|
"description": "A JavaScript framework for making Node.js API´s",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"MySQL GUID",
|
|
20
20
|
"JWT",
|
|
21
21
|
"Scheduler",
|
|
22
|
-
"Deploy"
|
|
22
|
+
"Deploy",
|
|
23
|
+
"AI",
|
|
24
|
+
"MCP"
|
|
23
25
|
],
|
|
24
26
|
"author": "Arnaldo Liberal dos Santos - arnaldo.liberal@outlook.com",
|
|
25
27
|
"homepage": "https://beejs.org",
|