From 4787676155cf4e815088303ba471f60cbe933e74 Mon Sep 17 00:00:00 2001 From: liuhang <1016817543@qq.com> Date: Tue, 9 Jul 2019 16:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=AF=E5=8A=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6app.js=E3=80=81agent.js=EF=BC=8C=E5=B0=86app.beforeSta?= =?UTF-8?q?rt=E6=9B=BF=E6=8D=A2=E4=B8=BA=E6=96=B0=E7=89=88=E7=9A=84?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.js | 17 ++++++++++++++--- app.js | 16 +++++++++++++--- lib/loader.js | 6 +++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/agent.js b/agent.js index 92b0d38..4551bfb 100644 --- a/agent.js +++ b/agent.js @@ -1,5 +1,16 @@ 'use strict'; -module.exports = agent => { - require('./lib/loader')(agent); -}; +class AgentBootHook { + + constructor(agent) { + this.agent = agent; + } + + async didLoad() { + // 请将你的插件项目中 app.beforeStart 中的代码置于此处。 + await require('./lib/loader')(this.agent); + } + +} + +module.exports = AgentBootHook; diff --git a/app.js b/app.js index 1d56502..8a52604 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,16 @@ 'use strict'; -module.exports = app => { - require('./lib/loader')(app); -}; +class AppBootHook { + constructor(app) { + this.app = app; + } + + async didLoad() { + // 请将你的插件项目中 app.beforeStart 中的代码置于此处。 + await require('./lib/loader')(this.app); + } + +} + +module.exports = AppBootHook; \ No newline at end of file diff --git a/lib/loader.js b/lib/loader.js index 22eba2f..990ae50 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -36,9 +36,9 @@ module.exports = app => { }); } - app.beforeStart(async () => { - await Promise.all(databases.map(database => authenticate(database))); - }); + // app.beforeStart(async () => { + return Promise.all(databases.map(database => authenticate(database))); + // }); /** * load databse to app[config.delegate