ee-core 2.9.2 → 2.10.1
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/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +86 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +58 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* BaseContextClass is a base class that can be extended,
|
|
5
|
-
* it's instantiated in context level,
|
|
6
|
-
* {@link Helper}, {@link Service} is extending it.
|
|
7
|
-
*/
|
|
8
|
-
class BaseContextClass {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @class
|
|
12
|
-
* @param {Context} ctx - context instance
|
|
13
|
-
* @since 1.0.0
|
|
14
|
-
*/
|
|
15
|
-
constructor(ctx) {
|
|
16
|
-
/**
|
|
17
|
-
* @member {Application} BaseContextClass#app
|
|
18
|
-
* @since 1.0.0
|
|
19
|
-
*/
|
|
20
|
-
this.app = ctx;
|
|
21
|
-
/**
|
|
22
|
-
* @member {Config} BaseContextClass#config
|
|
23
|
-
* @since 1.0.0
|
|
24
|
-
*/
|
|
25
|
-
this.config = ctx.config;
|
|
26
|
-
/**
|
|
27
|
-
* @member {Service} BaseContextClass#service
|
|
28
|
-
* @since 1.0.0
|
|
29
|
-
*/
|
|
30
|
-
this.service = ctx.service;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = BaseContextClass;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BaseContextClass is a base class that can be extended,
|
|
5
|
+
* it's instantiated in context level,
|
|
6
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
7
|
+
*/
|
|
8
|
+
class BaseContextClass {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class
|
|
12
|
+
* @param {Context} ctx - context instance
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
/**
|
|
17
|
+
* @member {Application} BaseContextClass#app
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
this.app = ctx;
|
|
21
|
+
/**
|
|
22
|
+
* @member {Config} BaseContextClass#config
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
this.config = ctx.config;
|
|
26
|
+
/**
|
|
27
|
+
* @member {Service} BaseContextClass#service
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
this.service = ctx.service;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = BaseContextClass;
|
package/services/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
const EE = require('../ee');
|
|
2
|
-
|
|
3
|
-
const Services = {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 获取 all addon instances
|
|
7
|
-
*/
|
|
8
|
-
all() {
|
|
9
|
-
const { CoreApp } = EE;
|
|
10
|
-
if (!CoreApp) {
|
|
11
|
-
throw new Error('An unknown error or Services cannot be used by the jobs!');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const instances = CoreApp.service || null;
|
|
15
|
-
if (!instances) {
|
|
16
|
-
throw new Error('Services not exists or do not call directly at the top!');
|
|
17
|
-
};
|
|
18
|
-
return instances;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 获取 addon instance
|
|
23
|
-
*/
|
|
24
|
-
get(name) {
|
|
25
|
-
const instances = this.all();
|
|
26
|
-
|
|
27
|
-
const actions = name.split('.');
|
|
28
|
-
let obj = instances;
|
|
29
|
-
actions.forEach(key => {
|
|
30
|
-
obj = obj[key];
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (!obj) {
|
|
34
|
-
throw new Error(`Service class '${name}' not exists or do not call directly at the top!`);
|
|
35
|
-
};
|
|
36
|
-
return obj;
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
1
|
+
const EE = require('../ee');
|
|
2
|
+
|
|
3
|
+
const Services = {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取 all addon instances
|
|
7
|
+
*/
|
|
8
|
+
all() {
|
|
9
|
+
const { CoreApp } = EE;
|
|
10
|
+
if (!CoreApp) {
|
|
11
|
+
throw new Error('An unknown error or Services cannot be used by the jobs!');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const instances = CoreApp.service || null;
|
|
15
|
+
if (!instances) {
|
|
16
|
+
throw new Error('Services not exists or do not call directly at the top!');
|
|
17
|
+
};
|
|
18
|
+
return instances;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 获取 addon instance
|
|
23
|
+
*/
|
|
24
|
+
get(name) {
|
|
25
|
+
const instances = this.all();
|
|
26
|
+
|
|
27
|
+
const actions = name.split('.');
|
|
28
|
+
let obj = instances;
|
|
29
|
+
actions.forEach(key => {
|
|
30
|
+
obj = obj[key];
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!obj) {
|
|
34
|
+
throw new Error(`Service class '${name}' not exists or do not call directly at the top!`);
|
|
35
|
+
};
|
|
36
|
+
return obj;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
41
|
module.exports = Services;
|
package/socket/httpServer.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const is = require('is-type-of');
|
|
5
|
-
const Koa = require('koa');
|
|
6
|
-
const cors = require('koa2-cors');
|
|
7
|
-
const koaBody = require('koa-body');
|
|
8
|
-
const https = require('https');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
const _ = require('lodash');
|
|
12
|
-
const Log = require('../log');
|
|
13
|
-
const Ps = require('../ps');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* http server
|
|
17
|
-
*/
|
|
18
|
-
class HttpServer {
|
|
19
|
-
constructor (app) {
|
|
20
|
-
this.app = app;
|
|
21
|
-
this.options = this.app.config.httpServer;
|
|
22
|
-
|
|
23
|
-
if (this.options.enable == false) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let port = Ps.getHttpPort();
|
|
28
|
-
if (!port) {
|
|
29
|
-
throw new Error('[ee-core] [socket/HttpServer] http port required, and must be a number !');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this._create();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 创建服务
|
|
37
|
-
*/
|
|
38
|
-
_create () {
|
|
39
|
-
const app = this.app;
|
|
40
|
-
const httpServer = this.options;
|
|
41
|
-
const isHttps = httpServer?.https?.enable ?? false;
|
|
42
|
-
let sslOptions = {};
|
|
43
|
-
|
|
44
|
-
if (isHttps === true) {
|
|
45
|
-
httpServer.protocol = 'https://';
|
|
46
|
-
const keyFile = path.join(app.config.homeDir, httpServer.https.key);
|
|
47
|
-
const certFile = path.join(app.config.homeDir, httpServer.https.cert);
|
|
48
|
-
assert(fs.existsSync(keyFile), 'ssl key file is required');
|
|
49
|
-
assert(fs.existsSync(certFile), 'ssl cert file is required');
|
|
50
|
-
|
|
51
|
-
sslOptions.key = fs.readFileSync(keyFile);
|
|
52
|
-
sslOptions.cert = fs.readFileSync(certFile);
|
|
53
|
-
}
|
|
54
|
-
const url = httpServer.protocol + httpServer.host + ':' + httpServer.port;
|
|
55
|
-
const corsOptions = httpServer.cors;
|
|
56
|
-
|
|
57
|
-
const koaApp = new Koa();
|
|
58
|
-
koaApp
|
|
59
|
-
.use(cors(corsOptions))
|
|
60
|
-
.use(koaBody(httpServer.body))
|
|
61
|
-
.use(async (ctx, next) => {
|
|
62
|
-
ctx.eeApp = app;
|
|
63
|
-
await next();
|
|
64
|
-
})
|
|
65
|
-
.use(this._dispatch);
|
|
66
|
-
|
|
67
|
-
let msg = '[ee-core] [socket/http] server is: ' + url;
|
|
68
|
-
|
|
69
|
-
const listenOpt = {
|
|
70
|
-
host: httpServer.host,
|
|
71
|
-
port: httpServer.port
|
|
72
|
-
}
|
|
73
|
-
if (isHttps) {
|
|
74
|
-
https.createServer(sslOptions, koaApp.callback()).listen(listenOpt, (err) => {
|
|
75
|
-
msg = err ? err : msg;
|
|
76
|
-
Log.coreLogger.info(msg);
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
koaApp.listen(listenOpt, (e) => {
|
|
80
|
-
msg = e ? e : msg;
|
|
81
|
-
Log.coreLogger.info(msg);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 路由分发
|
|
88
|
-
*/
|
|
89
|
-
async _dispatch (ctx, next) {
|
|
90
|
-
const config = ctx.eeApp.config.httpServer;
|
|
91
|
-
let uriPath = ctx.request.path;
|
|
92
|
-
const method = ctx.request.method;
|
|
93
|
-
let params = ctx.request.query;
|
|
94
|
-
params = is.object(params) ? JSON.parse(JSON.stringify(params)) : {};
|
|
95
|
-
const body = ctx.request.body;
|
|
96
|
-
const files = ctx.request.files;
|
|
97
|
-
|
|
98
|
-
// 默认
|
|
99
|
-
ctx.response.status = 200;
|
|
100
|
-
|
|
101
|
-
// 添加到全局属性
|
|
102
|
-
ctx.eeApp.request = ctx.request;
|
|
103
|
-
ctx.eeApp.response = ctx.response;
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
// 找函数
|
|
107
|
-
// 去除开头的 '/'
|
|
108
|
-
if (uriPath.indexOf('/') == 0) {
|
|
109
|
-
uriPath = uriPath.substring(1);
|
|
110
|
-
}
|
|
111
|
-
// 过滤
|
|
112
|
-
if (_.includes(config.filterRequest.uris, uriPath)) {
|
|
113
|
-
ctx.response.body = config.filterRequest.returnData;
|
|
114
|
-
await next();
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
if (uriPath.slice(0, 10) != 'controller') {
|
|
118
|
-
uriPath = 'controller/' + uriPath;
|
|
119
|
-
}
|
|
120
|
-
const cmd = uriPath.split('/').join('.');
|
|
121
|
-
const args = (method == 'POST') ? (ctx.request.header['content-type'] && ctx.request.header['content-type'].startsWith('multipart/form-data;') ? files : body) : params;
|
|
122
|
-
args.files = ctx.request.files;
|
|
123
|
-
args.body = ctx.request.body;
|
|
124
|
-
args.query = ctx.request.query;
|
|
125
|
-
let fn = null;
|
|
126
|
-
if (is.string(cmd)) {
|
|
127
|
-
const actions = cmd.split('.');
|
|
128
|
-
let obj = ctx.eeApp;
|
|
129
|
-
actions.forEach(key => {
|
|
130
|
-
obj = obj[key];
|
|
131
|
-
if (!obj) throw new Error(`class or function '${key}' not exists`);
|
|
132
|
-
});
|
|
133
|
-
fn = obj;
|
|
134
|
-
}
|
|
135
|
-
if (!fn) throw new Error('function not exists');
|
|
136
|
-
|
|
137
|
-
const result = await fn.call(ctx.eeApp, args);
|
|
138
|
-
ctx.response.body = result;
|
|
139
|
-
} catch (err) {
|
|
140
|
-
Log.coreLogger.error('[ee-core/httpServer] throw error:', err);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
await next();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
module.exports = HttpServer;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const is = require('is-type-of');
|
|
5
|
+
const Koa = require('koa');
|
|
6
|
+
const cors = require('koa2-cors');
|
|
7
|
+
const koaBody = require('koa-body');
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const _ = require('lodash');
|
|
12
|
+
const Log = require('../log');
|
|
13
|
+
const Ps = require('../ps');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* http server
|
|
17
|
+
*/
|
|
18
|
+
class HttpServer {
|
|
19
|
+
constructor (app) {
|
|
20
|
+
this.app = app;
|
|
21
|
+
this.options = this.app.config.httpServer;
|
|
22
|
+
|
|
23
|
+
if (this.options.enable == false) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let port = Ps.getHttpPort();
|
|
28
|
+
if (!port) {
|
|
29
|
+
throw new Error('[ee-core] [socket/HttpServer] http port required, and must be a number !');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this._create();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 创建服务
|
|
37
|
+
*/
|
|
38
|
+
_create () {
|
|
39
|
+
const app = this.app;
|
|
40
|
+
const httpServer = this.options;
|
|
41
|
+
const isHttps = httpServer?.https?.enable ?? false;
|
|
42
|
+
let sslOptions = {};
|
|
43
|
+
|
|
44
|
+
if (isHttps === true) {
|
|
45
|
+
httpServer.protocol = 'https://';
|
|
46
|
+
const keyFile = path.join(app.config.homeDir, httpServer.https.key);
|
|
47
|
+
const certFile = path.join(app.config.homeDir, httpServer.https.cert);
|
|
48
|
+
assert(fs.existsSync(keyFile), 'ssl key file is required');
|
|
49
|
+
assert(fs.existsSync(certFile), 'ssl cert file is required');
|
|
50
|
+
|
|
51
|
+
sslOptions.key = fs.readFileSync(keyFile);
|
|
52
|
+
sslOptions.cert = fs.readFileSync(certFile);
|
|
53
|
+
}
|
|
54
|
+
const url = httpServer.protocol + httpServer.host + ':' + httpServer.port;
|
|
55
|
+
const corsOptions = httpServer.cors;
|
|
56
|
+
|
|
57
|
+
const koaApp = new Koa();
|
|
58
|
+
koaApp
|
|
59
|
+
.use(cors(corsOptions))
|
|
60
|
+
.use(koaBody(httpServer.body))
|
|
61
|
+
.use(async (ctx, next) => {
|
|
62
|
+
ctx.eeApp = app;
|
|
63
|
+
await next();
|
|
64
|
+
})
|
|
65
|
+
.use(this._dispatch);
|
|
66
|
+
|
|
67
|
+
let msg = '[ee-core] [socket/http] server is: ' + url;
|
|
68
|
+
|
|
69
|
+
const listenOpt = {
|
|
70
|
+
host: httpServer.host,
|
|
71
|
+
port: httpServer.port
|
|
72
|
+
}
|
|
73
|
+
if (isHttps) {
|
|
74
|
+
https.createServer(sslOptions, koaApp.callback()).listen(listenOpt, (err) => {
|
|
75
|
+
msg = err ? err : msg;
|
|
76
|
+
Log.coreLogger.info(msg);
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
koaApp.listen(listenOpt, (e) => {
|
|
80
|
+
msg = e ? e : msg;
|
|
81
|
+
Log.coreLogger.info(msg);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 路由分发
|
|
88
|
+
*/
|
|
89
|
+
async _dispatch (ctx, next) {
|
|
90
|
+
const config = ctx.eeApp.config.httpServer;
|
|
91
|
+
let uriPath = ctx.request.path;
|
|
92
|
+
const method = ctx.request.method;
|
|
93
|
+
let params = ctx.request.query;
|
|
94
|
+
params = is.object(params) ? JSON.parse(JSON.stringify(params)) : {};
|
|
95
|
+
const body = ctx.request.body;
|
|
96
|
+
const files = ctx.request.files;
|
|
97
|
+
|
|
98
|
+
// 默认
|
|
99
|
+
ctx.response.status = 200;
|
|
100
|
+
|
|
101
|
+
// 添加到全局属性
|
|
102
|
+
ctx.eeApp.request = ctx.request;
|
|
103
|
+
ctx.eeApp.response = ctx.response;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
// 找函数
|
|
107
|
+
// 去除开头的 '/'
|
|
108
|
+
if (uriPath.indexOf('/') == 0) {
|
|
109
|
+
uriPath = uriPath.substring(1);
|
|
110
|
+
}
|
|
111
|
+
// 过滤
|
|
112
|
+
if (_.includes(config.filterRequest.uris, uriPath)) {
|
|
113
|
+
ctx.response.body = config.filterRequest.returnData;
|
|
114
|
+
await next();
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
if (uriPath.slice(0, 10) != 'controller') {
|
|
118
|
+
uriPath = 'controller/' + uriPath;
|
|
119
|
+
}
|
|
120
|
+
const cmd = uriPath.split('/').join('.');
|
|
121
|
+
const args = (method == 'POST') ? (ctx.request.header['content-type'] && ctx.request.header['content-type'].startsWith('multipart/form-data;') ? files : body) : params;
|
|
122
|
+
args.files = ctx.request.files;
|
|
123
|
+
args.body = ctx.request.body;
|
|
124
|
+
args.query = ctx.request.query;
|
|
125
|
+
let fn = null;
|
|
126
|
+
if (is.string(cmd)) {
|
|
127
|
+
const actions = cmd.split('.');
|
|
128
|
+
let obj = ctx.eeApp;
|
|
129
|
+
actions.forEach(key => {
|
|
130
|
+
obj = obj[key];
|
|
131
|
+
if (!obj) throw new Error(`class or function '${key}' not exists`);
|
|
132
|
+
});
|
|
133
|
+
fn = obj;
|
|
134
|
+
}
|
|
135
|
+
if (!fn) throw new Error('function not exists');
|
|
136
|
+
|
|
137
|
+
const result = await fn.call(ctx.eeApp, args);
|
|
138
|
+
ctx.response.body = result;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
Log.coreLogger.error('[ee-core/httpServer] throw error:', err);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
await next();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
module.exports = HttpServer;
|
package/socket/index.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const IoServer = require('socket.io');
|
|
4
|
-
const IoClient = require('socket.io-client');
|
|
5
|
-
const Koa = require('koa');
|
|
6
|
-
const EESocketServer = Symbol('Ee#SocketServer');
|
|
7
|
-
const EEIpcServer = Symbol('Ee#IpcServer');
|
|
8
|
-
const EEHttpServer = Symbol('Ee#HttpServer');
|
|
9
|
-
|
|
10
|
-
const EeSocket = {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 提供基础库 - 避免用户重复安装
|
|
14
|
-
*/
|
|
15
|
-
Koa,
|
|
16
|
-
IoServer,
|
|
17
|
-
IoClient,
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 启动所有服务
|
|
21
|
-
*/
|
|
22
|
-
startAll(app) {
|
|
23
|
-
this._createSocketServer(app);
|
|
24
|
-
this._createHttpServer(app);
|
|
25
|
-
this._createIpcServer(app);
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 创建SocketServer
|
|
30
|
-
*/
|
|
31
|
-
_createSocketServer(app) {
|
|
32
|
-
const SocketServer = require('./socketServer');
|
|
33
|
-
this[EESocketServer] = new SocketServer(app);
|
|
34
|
-
|
|
35
|
-
return this[EESocketServer];
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 获取 Socket Server
|
|
40
|
-
*/
|
|
41
|
-
getSocketServer() {
|
|
42
|
-
return this[EESocketServer] || null;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 创建 Http Server
|
|
47
|
-
*/
|
|
48
|
-
_createHttpServer(app) {
|
|
49
|
-
const HttpServer = require('./httpServer');
|
|
50
|
-
this[EEHttpServer] = new HttpServer(app);
|
|
51
|
-
|
|
52
|
-
return this[EEHttpServer];
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 获取 Http Server
|
|
57
|
-
*/
|
|
58
|
-
getHttpServer() {
|
|
59
|
-
return this[EEHttpServer] || null;
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 创建 IPC Server
|
|
64
|
-
*/
|
|
65
|
-
_createIpcServer(app) {
|
|
66
|
-
const IpcServer = require('./ipcServer');
|
|
67
|
-
this[EEIpcServer] = new IpcServer(app);
|
|
68
|
-
|
|
69
|
-
return this[EEIpcServer];
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 获取 IPC Server
|
|
74
|
-
*/
|
|
75
|
-
getIpcServer() {
|
|
76
|
-
return this[EEIpcServer] || null;
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const IoServer = require('socket.io');
|
|
4
|
+
const IoClient = require('socket.io-client');
|
|
5
|
+
const Koa = require('koa');
|
|
6
|
+
const EESocketServer = Symbol('Ee#SocketServer');
|
|
7
|
+
const EEIpcServer = Symbol('Ee#IpcServer');
|
|
8
|
+
const EEHttpServer = Symbol('Ee#HttpServer');
|
|
9
|
+
|
|
10
|
+
const EeSocket = {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 提供基础库 - 避免用户重复安装
|
|
14
|
+
*/
|
|
15
|
+
Koa,
|
|
16
|
+
IoServer,
|
|
17
|
+
IoClient,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 启动所有服务
|
|
21
|
+
*/
|
|
22
|
+
startAll(app) {
|
|
23
|
+
this._createSocketServer(app);
|
|
24
|
+
this._createHttpServer(app);
|
|
25
|
+
this._createIpcServer(app);
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 创建SocketServer
|
|
30
|
+
*/
|
|
31
|
+
_createSocketServer(app) {
|
|
32
|
+
const SocketServer = require('./socketServer');
|
|
33
|
+
this[EESocketServer] = new SocketServer(app);
|
|
34
|
+
|
|
35
|
+
return this[EESocketServer];
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取 Socket Server
|
|
40
|
+
*/
|
|
41
|
+
getSocketServer() {
|
|
42
|
+
return this[EESocketServer] || null;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 创建 Http Server
|
|
47
|
+
*/
|
|
48
|
+
_createHttpServer(app) {
|
|
49
|
+
const HttpServer = require('./httpServer');
|
|
50
|
+
this[EEHttpServer] = new HttpServer(app);
|
|
51
|
+
|
|
52
|
+
return this[EEHttpServer];
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取 Http Server
|
|
57
|
+
*/
|
|
58
|
+
getHttpServer() {
|
|
59
|
+
return this[EEHttpServer] || null;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 创建 IPC Server
|
|
64
|
+
*/
|
|
65
|
+
_createIpcServer(app) {
|
|
66
|
+
const IpcServer = require('./ipcServer');
|
|
67
|
+
this[EEIpcServer] = new IpcServer(app);
|
|
68
|
+
|
|
69
|
+
return this[EEIpcServer];
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 获取 IPC Server
|
|
74
|
+
*/
|
|
75
|
+
getIpcServer() {
|
|
76
|
+
return this[EEIpcServer] || null;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
82
|
module.exports = EeSocket;
|
package/socket/io.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 该文件将废弃
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const IoServer = require('socket.io');
|
|
8
|
-
const IoClient = require('socket.io-client');
|
|
9
|
-
//const socketServer = require('./socketServer');
|
|
10
|
-
// const socketClient = require('./socketClient');
|
|
11
|
-
const Koa = require('koa');
|
|
12
|
-
|
|
13
|
-
const EeSocket = {
|
|
14
|
-
getServer: () => {
|
|
15
|
-
//return socketServer.getInstance();
|
|
16
|
-
},
|
|
17
|
-
getClient: () => {
|
|
18
|
-
//return socketClient.getInstance();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
IoServer,
|
|
25
|
-
IoClient,
|
|
26
|
-
EeSocket,
|
|
27
|
-
Koa
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 该文件将废弃
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const IoServer = require('socket.io');
|
|
8
|
+
const IoClient = require('socket.io-client');
|
|
9
|
+
//const socketServer = require('./socketServer');
|
|
10
|
+
// const socketClient = require('./socketClient');
|
|
11
|
+
const Koa = require('koa');
|
|
12
|
+
|
|
13
|
+
const EeSocket = {
|
|
14
|
+
getServer: () => {
|
|
15
|
+
//return socketServer.getInstance();
|
|
16
|
+
},
|
|
17
|
+
getClient: () => {
|
|
18
|
+
//return socketClient.getInstance();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
IoServer,
|
|
25
|
+
IoClient,
|
|
26
|
+
EeSocket,
|
|
27
|
+
Koa
|
|
28
28
|
};
|