binhend 1.5.15 → 2.0.0

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.
Files changed (40) hide show
  1. package/bin/commands/new-service.js +20 -0
  2. package/bin/commands/new-ui.js +21 -0
  3. package/bin/commands/test-project.js +5 -3
  4. package/bin/index.js +4 -0
  5. package/bin/templates/component/Service.js +0 -0
  6. package/bin/templates/component/UI.js +8 -0
  7. package/bin/templates/component/ui/Component.js +26 -0
  8. package/bin/templates/component/ui/Service.js +7 -0
  9. package/bin/templates/component/ui/Style.css +3 -0
  10. package/bin/templates/component/ui/UI.js +17 -0
  11. package/bin/templates/frontend/src/favicon.png +0 -0
  12. package/bin/templates/frontend/src/index.html +5 -0
  13. package/bin/templates/frontend/src/style.css +3 -0
  14. package/bin/utils/cmdRun.js +20 -19
  15. package/package.json +3 -3
  16. package/src/api.js +84 -58
  17. package/src/binh.js +15 -62
  18. package/src/configuration.js +29 -99
  19. package/src/csd/controller.js +93 -0
  20. package/src/csd/dao.js +17 -0
  21. package/src/csd/index.js +15 -0
  22. package/src/csd/service.js +58 -0
  23. package/src/middleware/parseBasicAuthToken.js +11 -0
  24. package/src/server.js +4 -50
  25. package/src/utils/bromise.js +20 -0
  26. package/src/utils/httpCodes.js +69 -0
  27. package/src/utils/typeOf.js +78 -0
  28. package/src/{component.build.js → web/component.build.js} +1 -0
  29. package/src/{component.format.js → web/component.format.js} +1 -0
  30. package/src/web/component.method.js +141 -0
  31. package/src/web/index.js +46 -0
  32. package/src/binh.server.app.js +0 -78
  33. package/src/binh.server.config.js +0 -80
  34. package/src/cors.js +0 -17
  35. package/src/enum.httpCodes.js +0 -49
  36. /package/src/{cryptography.js → security.js} +0 -0
  37. /package/src/{binh.web.builder.js → web/binh.web.builder.js} +0 -0
  38. /package/src/{code.js → web/code.js} +0 -0
  39. /package/src/{component.file.js → web/component.file.js} +0 -0
  40. /package/src/{component.js → web/component.js} +0 -0
@@ -1,78 +0,0 @@
1
-
2
- const os = require('os');
3
- const cluster = require('cluster');
4
- const path = require('path');
5
- const { Server } = require('./server');
6
- const { APIs, Router, HttpError } = require('./api');
7
-
8
- const maxcpus = os.cpus().length;
9
-
10
- function ServerApp(binh, Binh, configloader) {
11
- var rootpath = Binh.getRootpath(),
12
- forkcount = 0, enabledCORS, pathAPI, portNumber;
13
-
14
- binh.router = function(module) {
15
- return Router(module);
16
- };
17
-
18
- binh.HttpError = HttpError;
19
-
20
- Binh.api = function(apiPath) {
21
- pathAPI = path.join(rootpath, apiPath);
22
- return Binh;
23
- };
24
-
25
- Binh.cors = function(input) {
26
- enabledCORS = input instanceof Function ? input : (input === false ? false : true);
27
- return Binh;
28
- };
29
-
30
- Binh.cluster = {
31
- fork: function(number) {
32
- forkcount = Math.max(0, number >= 0 ? number : maxcpus + number);
33
- return Binh;
34
- },
35
- max: function() {
36
- forkcount = maxcpus;
37
- return Binh;
38
- }
39
- };
40
-
41
- Binh.port = function(port) {
42
- if (typeof port === 'number') {
43
- portNumber = port;
44
- }
45
- else if (typeof port === 'string') {
46
- portNumber = binh.config(port);
47
- }
48
- return Binh;
49
- };
50
-
51
- Binh.start = function(callback) {
52
- if (forkcount > 0 && cluster.isMaster) {
53
- for (var i = 0; i < forkcount; i++) {
54
- cluster.fork();
55
- }
56
- }
57
- else {
58
- launch(callback);
59
- }
60
- };
61
-
62
- function launch(callback) {
63
- configloader.done(function(configs) {
64
- new Server({
65
- port: portNumber,
66
- api: APIs(pathAPI),
67
- cors: enabledCORS,
68
- web: Binh.web.value,
69
- callback: callback,
70
- configs: configs
71
- });
72
- });
73
- }
74
- }
75
-
76
- module.exports = {
77
- ServerApp
78
- };
@@ -1,80 +0,0 @@
1
-
2
- const { ConfigLoader } = require('./configuration');
3
-
4
- function ServerConfig(binh, Binh) {
5
-
6
- var config = {}, loadConfigs = null, groupLoadConfigs = [], configloader = new ConfigLoader(config);
7
-
8
- binh.config = function(key) {
9
- if (typeof key !== 'string') return config;
10
-
11
- if (config.hasOwnProperty(key)) return config[key];
12
-
13
- var pointer = config, keys = key.split('.'), length = keys.length;
14
-
15
- try {
16
- for (var i = 0; i < length; i++) {
17
- pointer = pointer[keys[i]];
18
- }
19
- return pointer;
20
- }
21
- catch (e) {
22
- return undefined;
23
- }
24
- };
25
-
26
- binh.config.reload = function() {
27
- return new Promise(function(resolve) {
28
- var loader = new ConfigLoader(config);
29
-
30
- groupLoadConfigs.forEach(function(loadConfigs) {
31
- if (loadConfigs instanceof Function) {
32
- loadConfigs(loader);
33
- }
34
- });
35
-
36
- loader.done(resolve);
37
- });
38
- };
39
-
40
- binh.config.loader = function() {
41
- return new ConfigLoader(config);
42
- };
43
-
44
- Binh.config = function(module, doneCallback) {
45
- if (module instanceof Function) {
46
- loadConfigs = module;
47
- }
48
- else if (typeof module === 'string') {
49
- loadConfigs = binh(module);
50
- }
51
- else {
52
- loadConfigs = defaultConfigLoader;
53
- }
54
-
55
- loadConfigs(configloader);
56
-
57
- if (doneCallback instanceof Function) configloader.done(doneCallback);
58
-
59
- groupLoadConfigs.push(loadConfigs);
60
-
61
- return Binh;
62
- };
63
-
64
- return configloader;
65
- }
66
-
67
- function defaultConfigLoader(loader) {
68
- loader.object(process.env);
69
-
70
- try {
71
- loader.file('.env');
72
- }
73
- catch(e) {}
74
-
75
- loader.cli();
76
- }
77
-
78
- module.exports = {
79
- ServerConfig
80
- };
package/src/cors.js DELETED
@@ -1,17 +0,0 @@
1
-
2
- function defaultCORS(req, res, next) {
3
- res.header('Access-Control-Allow-Origin', req.get('Origin') || '*');
4
- res.header('Access-Control-Allow-Credentials', 'true');
5
- res.header('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
6
- res.header('Access-Control-Expose-Headers', 'Content-Length');
7
- res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range');
8
- if (req.method === 'OPTIONS') {
9
- return res.send(200);
10
- } else {
11
- return next();
12
- }
13
- }
14
-
15
- module.exports = {
16
- defaultCORS
17
- };
@@ -1,49 +0,0 @@
1
-
2
- const HttpCodes = {
3
- CONTINUE: 100,
4
- SWITCHING_PROTOCOLS: 101,
5
- PROCESSING: 102,
6
- EARLY_HINTS: 103,
7
-
8
- OK: 200,
9
- CREATED: 201,
10
- ACCEPTED: 202,
11
- NON_AUTHORITATIVE_INFORMATION: 203,
12
- NO_CONTENT: 204,
13
- RESET_CONTENT: 205,
14
- PARTIAL_CONTENT: 206,
15
- MULTI_STATUS: 207,
16
- ALREADY_REPORTED: 208,
17
- IM_USED: 226,
18
-
19
- MULTIPLE_CHOICES: 300,
20
- MOVED_PERMANENTLY: 301,
21
- FOUND: 302,
22
- SEE_OTHER: 303,
23
- NOT_MODIFIED: 304,
24
- USE_PROXY: 305,
25
- UNUSED: 306,
26
- TEMPORARY_REDIRECT: 307,
27
- PERMANENT_REDIRECT: 308,
28
-
29
- BAD_REQUEST: 400,
30
- UNAUTHORIZED: 401,
31
-
32
- FORBIDDEN: 403,
33
- NOT_FOUND: 404,
34
- METHOD_NOT_ALLOWED: 405,
35
- NOT_ACCEPTABLE: 406,
36
-
37
- REQUEST_TIMEOUT: 408,
38
- I_AM_A_TEAPOT: 418,
39
-
40
- INTERNAL_SERVER_ERROR: 500,
41
- NOT_IMPLEMENTED: 501,
42
- BAD_GATEWAY: 502,
43
- SERVICE_UNAVAILABLE: 503,
44
- GATEWAY_TIMEOUT: 504
45
- };
46
-
47
- module.exports = {
48
- HttpCodes
49
- };
File without changes
File without changes
File without changes