@bee.js/node 0.0.68 → 0.0.69

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.
@@ -1,20 +1,27 @@
1
1
  const log = require("./log");
2
2
  const beeDEV = require("../DEV/beeDEV");
3
+ const http = require("http");
3
4
  const https = require("https");
4
5
  const fs = require("fs");
6
+ const WebSocket = require("ws");
5
7
 
6
- module.exports = function (app, { ws } = {}) {
8
+ const servers = { http: null, https: null };
9
+
10
+ module.exports = function (app, options = {}) {
7
11
  const ports = (global.configs.port || global.configs.ports || 1987.443)
8
12
  .toString()
9
13
  .split(".");
10
14
 
11
- const callback = () => {
12
- ws?.({ app });
13
- };
14
-
15
15
  app.post("/beedev/:action", beeDEV); //TODO check security and create a method for define enable/disable
16
16
 
17
- app.listen(ports[0], callback);
17
+ servers.http = http.createServer(app);
18
+
19
+ if (options.ws) {
20
+ const ws = new WebSocket.Server({ server: servers.http });
21
+ options.ws({ ws });
22
+ }
23
+
24
+ servers.http.listen(ports[0]);
18
25
 
19
26
  log(`${configs.name || "Bee.js"} started.`);
20
27
  log(`${configs.name || "System"} listening at http://localhost:${ports[0]}`);
@@ -33,11 +40,16 @@ module.exports = function (app, { ws } = {}) {
33
40
  }
34
41
  : {};
35
42
 
36
- const server = https
37
- .createServer(certificate, app)
38
- .listen(ports[1], callback);
43
+ servers.https = https.createServer(certificate, app);
44
+
45
+ if (options.ws) {
46
+ const wss = new WebSocket.Server({ server: servers.https });
47
+ options.ws({ ws: wss });
48
+ }
49
+
50
+ servers.https.listen(ports[1]);
39
51
 
40
52
  log(`${configs.name || "Bee.js"} listening at https://localhost:${ports[1]}`);
41
53
 
42
- return server;
54
+ return servers;
43
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.68",
3
+ "version": "0.0.69",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,6 +35,7 @@
35
35
  "mysql2": "3.11.0",
36
36
  "nodemon": "^2.0.6",
37
37
  "util": "^0.12.2",
38
- "uuid": "^9.0.0"
38
+ "uuid": "^9.0.0",
39
+ "ws": "^8.18.1"
39
40
  }
40
41
  }