ee-core 1.2.7-beta.4 → 1.2.7

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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/bin/tools.js +22 -22
  4. package/config/config.default.js +247 -247
  5. package/core/index.js +12 -12
  6. package/core/lib/ee.js +209 -209
  7. package/core/lib/loader/context_loader.js +105 -105
  8. package/core/lib/loader/ee_loader.js +451 -451
  9. package/core/lib/loader/file_loader.js +262 -262
  10. package/core/lib/loader/mixin/config.js +138 -138
  11. package/core/lib/loader/mixin/controller.js +123 -123
  12. package/core/lib/loader/mixin/service.js +29 -29
  13. package/core/lib/utils/base_context_class.js +34 -34
  14. package/core/lib/utils/index.js +100 -100
  15. package/core/lib/utils/sequencify.js +59 -59
  16. package/core/lib/utils/timing.js +77 -77
  17. package/index.js +49 -49
  18. package/lib/appLoader.js +45 -45
  19. package/lib/application.js +80 -80
  20. package/lib/baseApp.js +118 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +326 -326
  23. package/lib/helper.js +51 -51
  24. package/lib/httpclient.js +136 -136
  25. package/lib/logger.js +46 -46
  26. package/lib/socket/httpServer.js +104 -104
  27. package/lib/socket/io.js +23 -23
  28. package/lib/socket/ipcServer.js +128 -128
  29. package/lib/socket/socketClient.js +50 -50
  30. package/lib/socket/socketServer.js +76 -76
  31. package/lib/socket/start.js +22 -22
  32. package/lib/storage/appStorage.js +13 -13
  33. package/lib/storage/index.js +21 -21
  34. package/lib/storage/lowdbStorage.js +143 -143
  35. package/package.json +45 -45
  36. package/resource/loading.html +21 -21
  37. package/resource/view_example.html +21 -21
  38. package/tools/codeCompress.js +204 -204
  39. package/tools/replaceDist.js +76 -76
  40. package/utils/common.js +30 -30
  41. package/utils/index.js +207 -207
  42. package/utils/wrap.js +37 -37
package/lib/helper.js CHANGED
@@ -1,52 +1,52 @@
1
- 'use strict';
2
-
3
- const is = require('electron-is');
4
- const { app } = require('electron');
5
-
6
- /**
7
- * application quit
8
- *
9
- * @return {undefined}
10
- */
11
- exports.appQuit = function () {
12
- MAIN_WINDOW.destroy();
13
- app.quit();
14
- }
15
-
16
- /**
17
- * get Platform
18
- *
19
- * @return {Object}
20
- */
21
- exports.getPlatform = function () {
22
- let platform = null;
23
- let arch = null;
24
- if (is.windows()) {
25
- platform = 'windows';
26
- } else if (is.macOS()) {
27
- platform = 'macOS';
28
- } else if (is.linux()) {
29
- platform = 'linux';
30
- } else {
31
- platform = 'other';
32
- }
33
-
34
- if (is.x86()) {
35
- arch = '32';
36
- } else if (is.x64()) {
37
- arch = '64';
38
- } else if (process.arch == 'arm') {
39
- arch = 'arm32';
40
- } else if (process.arch == 'arm64') {
41
- arch = 'arm64';
42
- } else {
43
- arch = 'other';
44
- }
45
-
46
- const platfromObj = {
47
- platform: platform,
48
- arch: arch
49
- };
50
-
51
- return platfromObj;
1
+ 'use strict';
2
+
3
+ const is = require('electron-is');
4
+ const { app } = require('electron');
5
+
6
+ /**
7
+ * application quit
8
+ *
9
+ * @return {undefined}
10
+ */
11
+ exports.appQuit = function () {
12
+ MAIN_WINDOW.destroy();
13
+ app.quit();
14
+ }
15
+
16
+ /**
17
+ * get Platform
18
+ *
19
+ * @return {Object}
20
+ */
21
+ exports.getPlatform = function () {
22
+ let platform = null;
23
+ let arch = null;
24
+ if (is.windows()) {
25
+ platform = 'windows';
26
+ } else if (is.macOS()) {
27
+ platform = 'macOS';
28
+ } else if (is.linux()) {
29
+ platform = 'linux';
30
+ } else {
31
+ platform = 'other';
32
+ }
33
+
34
+ if (is.x86()) {
35
+ arch = '32';
36
+ } else if (is.x64()) {
37
+ arch = '64';
38
+ } else if (process.arch == 'arm') {
39
+ arch = 'arm32';
40
+ } else if (process.arch == 'arm64') {
41
+ arch = 'arm64';
42
+ } else {
43
+ arch = 'other';
44
+ }
45
+
46
+ const platfromObj = {
47
+ platform: platform,
48
+ arch: arch
49
+ };
50
+
51
+ return platfromObj;
52
52
  }
package/lib/httpclient.js CHANGED
@@ -1,136 +1,136 @@
1
- 'use strict';
2
-
3
- const Agent = require('agentkeepalive');
4
- const HttpsAgent = require('agentkeepalive').HttpsAgent;
5
- const urllib = require('urllib');
6
- const ms = require('humanize-ms');
7
- const { FrameworkBaseError } = require('egg-errors');
8
-
9
- class HttpClientError extends FrameworkBaseError {
10
- get module() {
11
- return 'httpclient';
12
- }
13
- }
14
-
15
- class HttpClient extends urllib.HttpClient2 {
16
- constructor(app) {
17
- normalizeConfig(app);
18
- const config = app.config.httpclient;
19
- super({
20
- app,
21
- defaultArgs: config.request,
22
- agent: new Agent(config.httpAgent),
23
- httpsAgent: new HttpsAgent(config.httpsAgent),
24
- });
25
- this.app = app;
26
- }
27
-
28
- request(url, args, callback) {
29
- if (typeof args === 'function') {
30
- callback = args;
31
- args = null;
32
- }
33
-
34
- args = args || {};
35
-
36
- // the callback style
37
- if (callback) {
38
- //this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
39
- super.request(url, args)
40
- .then(result => process.nextTick(() => callback(null, result.data, result.res)))
41
- .catch(err => process.nextTick(() => callback(err)));
42
- return;
43
- }
44
-
45
- // the Promise style
46
- return super.request(url, args)
47
- .catch(err => {
48
- if (err.code === 'ENETUNREACH') {
49
- throw HttpClientError.create(err.message, err.code);
50
- }
51
- throw err;
52
- });
53
- }
54
-
55
- curl(url, args, callback) {
56
- return this.request(url, args, callback);
57
- }
58
-
59
- requestThunk(url, args) {
60
- //this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
61
- return callback => {
62
- this.request(url, args, (err, data, res) => {
63
- if (err) {
64
- return callback(err);
65
- }
66
- callback(null, {
67
- data,
68
- status: res.status,
69
- headers: res.headers,
70
- res,
71
- });
72
- });
73
- };
74
- }
75
- }
76
-
77
- function normalizeConfig(app) {
78
- const config = app.config.httpclient;
79
-
80
- // compatibility
81
- if (typeof config.keepAlive === 'boolean') {
82
- config.httpAgent.keepAlive = config.keepAlive;
83
- config.httpsAgent.keepAlive = config.keepAlive;
84
- }
85
- if (config.timeout) {
86
- config.timeout = ms(config.timeout);
87
- config.httpAgent.timeout = config.timeout;
88
- config.httpsAgent.timeout = config.timeout;
89
- }
90
- // compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
91
- if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
92
- config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
93
- delete config.freeSocketKeepAliveTimeout;
94
- }
95
- if (config.freeSocketTimeout) {
96
- config.freeSocketTimeout = ms(config.freeSocketTimeout);
97
- config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
98
- config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
99
- } else {
100
- // compatibility agent.freeSocketKeepAliveTimeout
101
- if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
102
- config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
103
- delete config.httpAgent.freeSocketKeepAliveTimeout;
104
- }
105
- if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
106
- config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
107
- delete config.httpsAgent.freeSocketKeepAliveTimeout;
108
- }
109
- }
110
-
111
- if (typeof config.maxSockets === 'number') {
112
- config.httpAgent.maxSockets = config.maxSockets;
113
- config.httpsAgent.maxSockets = config.maxSockets;
114
- }
115
- if (typeof config.maxFreeSockets === 'number') {
116
- config.httpAgent.maxFreeSockets = config.maxFreeSockets;
117
- config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
118
- }
119
-
120
- if (config.httpAgent.timeout < 30000) {
121
- app.coreLogger.warn('[ee:httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
122
- config.httpAgent.timeout);
123
- config.httpAgent.timeout = 30000;
124
- }
125
- if (config.httpsAgent.timeout < 30000) {
126
- app.coreLogger.warn('[ee:httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
127
- config.httpsAgent.timeout);
128
- config.httpsAgent.timeout = 30000;
129
- }
130
-
131
- if (typeof config.request.timeout === 'string') {
132
- config.request.timeout = ms(config.request.timeout);
133
- }
134
- }
135
-
136
- module.exports = HttpClient;
1
+ 'use strict';
2
+
3
+ const Agent = require('agentkeepalive');
4
+ const HttpsAgent = require('agentkeepalive').HttpsAgent;
5
+ const urllib = require('urllib');
6
+ const ms = require('humanize-ms');
7
+ const { FrameworkBaseError } = require('egg-errors');
8
+
9
+ class HttpClientError extends FrameworkBaseError {
10
+ get module() {
11
+ return 'httpclient';
12
+ }
13
+ }
14
+
15
+ class HttpClient extends urllib.HttpClient2 {
16
+ constructor(app) {
17
+ normalizeConfig(app);
18
+ const config = app.config.httpclient;
19
+ super({
20
+ app,
21
+ defaultArgs: config.request,
22
+ agent: new Agent(config.httpAgent),
23
+ httpsAgent: new HttpsAgent(config.httpsAgent),
24
+ });
25
+ this.app = app;
26
+ }
27
+
28
+ request(url, args, callback) {
29
+ if (typeof args === 'function') {
30
+ callback = args;
31
+ args = null;
32
+ }
33
+
34
+ args = args || {};
35
+
36
+ // the callback style
37
+ if (callback) {
38
+ //this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
39
+ super.request(url, args)
40
+ .then(result => process.nextTick(() => callback(null, result.data, result.res)))
41
+ .catch(err => process.nextTick(() => callback(err)));
42
+ return;
43
+ }
44
+
45
+ // the Promise style
46
+ return super.request(url, args)
47
+ .catch(err => {
48
+ if (err.code === 'ENETUNREACH') {
49
+ throw HttpClientError.create(err.message, err.code);
50
+ }
51
+ throw err;
52
+ });
53
+ }
54
+
55
+ curl(url, args, callback) {
56
+ return this.request(url, args, callback);
57
+ }
58
+
59
+ requestThunk(url, args) {
60
+ //this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
61
+ return callback => {
62
+ this.request(url, args, (err, data, res) => {
63
+ if (err) {
64
+ return callback(err);
65
+ }
66
+ callback(null, {
67
+ data,
68
+ status: res.status,
69
+ headers: res.headers,
70
+ res,
71
+ });
72
+ });
73
+ };
74
+ }
75
+ }
76
+
77
+ function normalizeConfig(app) {
78
+ const config = app.config.httpclient;
79
+
80
+ // compatibility
81
+ if (typeof config.keepAlive === 'boolean') {
82
+ config.httpAgent.keepAlive = config.keepAlive;
83
+ config.httpsAgent.keepAlive = config.keepAlive;
84
+ }
85
+ if (config.timeout) {
86
+ config.timeout = ms(config.timeout);
87
+ config.httpAgent.timeout = config.timeout;
88
+ config.httpsAgent.timeout = config.timeout;
89
+ }
90
+ // compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
91
+ if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
92
+ config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
93
+ delete config.freeSocketKeepAliveTimeout;
94
+ }
95
+ if (config.freeSocketTimeout) {
96
+ config.freeSocketTimeout = ms(config.freeSocketTimeout);
97
+ config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
98
+ config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
99
+ } else {
100
+ // compatibility agent.freeSocketKeepAliveTimeout
101
+ if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
102
+ config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
103
+ delete config.httpAgent.freeSocketKeepAliveTimeout;
104
+ }
105
+ if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
106
+ config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
107
+ delete config.httpsAgent.freeSocketKeepAliveTimeout;
108
+ }
109
+ }
110
+
111
+ if (typeof config.maxSockets === 'number') {
112
+ config.httpAgent.maxSockets = config.maxSockets;
113
+ config.httpsAgent.maxSockets = config.maxSockets;
114
+ }
115
+ if (typeof config.maxFreeSockets === 'number') {
116
+ config.httpAgent.maxFreeSockets = config.maxFreeSockets;
117
+ config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
118
+ }
119
+
120
+ if (config.httpAgent.timeout < 30000) {
121
+ app.coreLogger.warn('[ee:httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
122
+ config.httpAgent.timeout);
123
+ config.httpAgent.timeout = 30000;
124
+ }
125
+ if (config.httpsAgent.timeout < 30000) {
126
+ app.coreLogger.warn('[ee:httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
127
+ config.httpsAgent.timeout);
128
+ config.httpsAgent.timeout = 30000;
129
+ }
130
+
131
+ if (typeof config.request.timeout === 'string') {
132
+ config.request.timeout = ms(config.request.timeout);
133
+ }
134
+ }
135
+
136
+ module.exports = HttpClient;
package/lib/logger.js CHANGED
@@ -1,47 +1,47 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core:logger');
4
- const Loggers = require('egg-logger').EggLoggers;
5
- const assert = require('assert');
6
-
7
- class Logger {
8
- constructor (config) {
9
- debug('Loaded logger');
10
- assert(Object.keys(config).length != 0, `logger config is null`);
11
- this.eggLogger = this.init(config);
12
- }
13
-
14
- /**
15
- * 单例
16
- */
17
- static getInstance (config = {}) {
18
- if (typeof this.instance === 'object') {
19
- return this.instance.eggLogger;
20
- }
21
-
22
- this.instance = new Logger(config);
23
-
24
- // 返回egg-logger实例
25
- return this.instance.eggLogger;
26
- }
27
-
28
- /**
29
- * 初始化模块
30
- */
31
- init(config) {
32
- const loggerConfig = config.logger;
33
- loggerConfig.type = 'application'; // application、agent
34
-
35
- if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
- loggerConfig.level = 'INFO';
37
- }
38
-
39
- const loggers = new Loggers(config);
40
-
41
- loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
-
43
- return loggers;
44
- };
45
- }
46
-
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('ee-core:logger');
4
+ const Loggers = require('egg-logger').EggLoggers;
5
+ const assert = require('assert');
6
+
7
+ class Logger {
8
+ constructor (config) {
9
+ debug('Loaded logger');
10
+ assert(Object.keys(config).length != 0, `logger config is null`);
11
+ this.eggLogger = this.init(config);
12
+ }
13
+
14
+ /**
15
+ * 单例
16
+ */
17
+ static getInstance (config = {}) {
18
+ if (typeof this.instance === 'object') {
19
+ return this.instance.eggLogger;
20
+ }
21
+
22
+ this.instance = new Logger(config);
23
+
24
+ // 返回egg-logger实例
25
+ return this.instance.eggLogger;
26
+ }
27
+
28
+ /**
29
+ * 初始化模块
30
+ */
31
+ init(config) {
32
+ const loggerConfig = config.logger;
33
+ loggerConfig.type = 'application'; // application、agent
34
+
35
+ if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
+ loggerConfig.level = 'INFO';
37
+ }
38
+
39
+ const loggers = new Loggers(config);
40
+
41
+ loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
+
43
+ return loggers;
44
+ };
45
+ }
46
+
47
47
  module.exports = Logger;
@@ -1,105 +1,105 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const is = require('is-type-of');
5
- const Koa = require('koa');
6
- const BodyParser = require('koa-bodyparser');
7
- const cors = require('koa2-cors');
8
-
9
- /**
10
- * http server
11
- */
12
- class HttpServer {
13
- constructor (app) {
14
- this.app = app;
15
- const options = this.app.config.httpServer;
16
-
17
- if (!options.enable) {
18
- return;
19
- }
20
-
21
- let port = process.env.EE_HTTP_PORT ? parseInt(process.env.EE_HTTP_PORT) : parseInt(this.getHttpPort());
22
- assert(typeof port === 'number', 'http port required, and must be a number');
23
-
24
- this.create();
25
- }
26
-
27
- /**
28
- * 创建服务
29
- */
30
- create () {
31
- const self = this;
32
- const httpServer = this.app.config.httpServer;
33
- const url = httpServer.protocol + httpServer.host + ':' + httpServer.port;
34
- const corsOptions = httpServer.cors;
35
-
36
- const koaApp = new Koa();
37
- const bodyparser= new BodyParser();
38
-
39
- koaApp
40
- .use(cors(corsOptions))
41
- .use(bodyparser)
42
- .use(async (ctx, next) => {
43
- ctx.eeApp = self.app;
44
- await next();
45
- })
46
- .use(this.dispatch);
47
-
48
- koaApp.listen(httpServer.port, () => {
49
- self.app.coreLogger.info('[ee-core:http:server] http server is:', url);
50
- });
51
- }
52
-
53
- /**
54
- * 路由分发
55
- */
56
- async dispatch (ctx, next) {
57
- let uriPath = ctx.request.path;
58
- const method = ctx.request.method;
59
- let params = ctx.request.query;
60
- params = is.object(params) ? JSON.parse(JSON.stringify(params)) : {};
61
- const body = ctx.request.body;
62
- // 添加到全局属性
63
- ctx.eeApp.request = ctx.request;
64
- ctx.eeApp.response = ctx.response;
65
-
66
- try {
67
- // 找函数
68
- if (uriPath.indexOf('/') !== -1) {
69
- uriPath = uriPath.substring(1);
70
- }
71
- const cmd = uriPath.split('/').join('.');
72
- const args = (method == 'POST') ? body : params;
73
- let fn = null;
74
- if (is.string(cmd)) {
75
- const actions = cmd.split('.');
76
- let obj = ctx.eeApp;
77
- actions.forEach(key => {
78
- obj = obj[key];
79
- if (!obj) throw new Error(`class or function '${key}' not exists`);
80
- });
81
- fn = obj;
82
- }
83
- if (!fn) throw new Error('function not exists');
84
-
85
- const result = await fn.call(ctx.eeApp, args);
86
- ctx.response.status = 200;
87
- ctx.response.body = result;
88
- } catch (err) {
89
- ctx.eeApp.console.error('[ee-core:http:server] throw error:', err);
90
- }
91
-
92
- await next();
93
- }
94
-
95
- /**
96
- * 获取http端口
97
- */
98
- getHttpPort () {
99
- const cdb = this.getCoreDB();
100
- const port = cdb.getItem('config').httpServer.port;
101
- return parseInt(port);
102
- }
103
- }
104
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const is = require('is-type-of');
5
+ const Koa = require('koa');
6
+ const BodyParser = require('koa-bodyparser');
7
+ const cors = require('koa2-cors');
8
+
9
+ /**
10
+ * http server
11
+ */
12
+ class HttpServer {
13
+ constructor (app) {
14
+ this.app = app;
15
+ const options = this.app.config.httpServer;
16
+
17
+ if (!options.enable) {
18
+ return;
19
+ }
20
+
21
+ let port = process.env.EE_HTTP_PORT ? parseInt(process.env.EE_HTTP_PORT) : parseInt(this.getHttpPort());
22
+ assert(typeof port === 'number', 'http port required, and must be a number');
23
+
24
+ this.create();
25
+ }
26
+
27
+ /**
28
+ * 创建服务
29
+ */
30
+ create () {
31
+ const self = this;
32
+ const httpServer = this.app.config.httpServer;
33
+ const url = httpServer.protocol + httpServer.host + ':' + httpServer.port;
34
+ const corsOptions = httpServer.cors;
35
+
36
+ const koaApp = new Koa();
37
+ const bodyparser= new BodyParser();
38
+
39
+ koaApp
40
+ .use(cors(corsOptions))
41
+ .use(bodyparser)
42
+ .use(async (ctx, next) => {
43
+ ctx.eeApp = self.app;
44
+ await next();
45
+ })
46
+ .use(this.dispatch);
47
+
48
+ koaApp.listen(httpServer.port, () => {
49
+ self.app.coreLogger.info('[ee-core:http:server] http server is:', url);
50
+ });
51
+ }
52
+
53
+ /**
54
+ * 路由分发
55
+ */
56
+ async dispatch (ctx, next) {
57
+ let uriPath = ctx.request.path;
58
+ const method = ctx.request.method;
59
+ let params = ctx.request.query;
60
+ params = is.object(params) ? JSON.parse(JSON.stringify(params)) : {};
61
+ const body = ctx.request.body;
62
+ // 添加到全局属性
63
+ ctx.eeApp.request = ctx.request;
64
+ ctx.eeApp.response = ctx.response;
65
+
66
+ try {
67
+ // 找函数
68
+ if (uriPath.indexOf('/') !== -1) {
69
+ uriPath = uriPath.substring(1);
70
+ }
71
+ const cmd = uriPath.split('/').join('.');
72
+ const args = (method == 'POST') ? body : params;
73
+ let fn = null;
74
+ if (is.string(cmd)) {
75
+ const actions = cmd.split('.');
76
+ let obj = ctx.eeApp;
77
+ actions.forEach(key => {
78
+ obj = obj[key];
79
+ if (!obj) throw new Error(`class or function '${key}' not exists`);
80
+ });
81
+ fn = obj;
82
+ }
83
+ if (!fn) throw new Error('function not exists');
84
+
85
+ const result = await fn.call(ctx.eeApp, args);
86
+ ctx.response.status = 200;
87
+ ctx.response.body = result;
88
+ } catch (err) {
89
+ ctx.eeApp.console.error('[ee-core:http:server] throw error:', err);
90
+ }
91
+
92
+ await next();
93
+ }
94
+
95
+ /**
96
+ * 获取http端口
97
+ */
98
+ getHttpPort () {
99
+ const cdb = this.getCoreDB();
100
+ const port = cdb.getItem('config').httpServer.port;
101
+ return parseInt(port);
102
+ }
103
+ }
104
+
105
105
  module.exports = HttpServer;