Skip to content

Commit d968feb

Browse files
committed
art: 调整顺序
1 parent 7d7d909 commit d968feb

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

src/plugins/factory/Lifecycle.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ module.exports = class Lifecycle {
99
this.__init__();
1010
}
1111

12-
// config(root) {
13-
// return this.__register__('config', root);
14-
// }
15-
16-
// service(root) {
17-
// return this.__register__('service', root);
18-
// }
19-
20-
// helper(root) {
21-
// return this.__register__('helper', root);
22-
// }
23-
24-
// middleware(root) {
25-
// return this.__register__('middleware', root);
26-
// }
27-
28-
// plugin(root) {
29-
// return this.__register__('plugin', root);
30-
// }
31-
3212
__init__() {
3313
const app = this.app;
3414
const config = app.$config || {};

src/plugins/factory/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ module.exports = async function(api, info = {}) {
3737

3838
app.server = server;
3939

40+
const portfinder = require('portfinder');
41+
const startPort = parseInt(process.env.PORT || apiContext.port || port || 3000);
42+
const _port = await portfinder.getPortPromise({
43+
port: startPort, // minimum port
44+
stopPort: startPort + 300, // maximum port
45+
});
46+
const _host = process.env.HOST || apiContext.host || host || '0.0.0.0';
47+
48+
// 基本信息
49+
const serverInfo = { protocol, host: _host, port: _port };
50+
app.server.info = serverInfo;
51+
4052
if (entries.length > 0) {
4153
await entries.reduce((chain, entry) => {
4254
const runApp = require(entry); // app.js
@@ -49,15 +61,7 @@ module.exports = async function(api, info = {}) {
4961
await runApp(app);
5062
}
5163

52-
const portfinder = require('portfinder');
53-
const startPort = parseInt(process.env.PORT || apiContext.port || port || 3000);
54-
const _port = await portfinder.getPortPromise({
55-
port: startPort, // minimum port
56-
stopPort: startPort + 300, // maximum port
57-
});
58-
const _host = process.env.HOST || apiContext.host || host || '0.0.0.0';
59-
60-
const ps = [ listen(app, { protocol, host: _host, port: _port }) ];
64+
const ps = [ listen(app, serverInfo) ];
6165
return Promise.all(ps).then(ress => {
6266
const res = { ...ress[0] };
6367
return res; // 只返回第一个配置

0 commit comments

Comments
 (0)