From 76ff783b80a9d9ffc01db1b434c25fedd6e27ca7 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 23 Nov 2017 22:10:23 +0800 Subject: [PATCH] fix: run dumpConfig at the last ready callback --- lib/egg.js | 3 ++- test/fixtures/apps/demo/app.js | 7 +++++++ test/fixtures/apps/demo/config/config.default.js | 2 ++ test/lib/egg.test.js | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/apps/demo/app.js diff --git a/lib/egg.js b/lib/egg.js index ca1d1e1fd0..8d9074f909 100644 --- a/lib/egg.js +++ b/lib/egg.js @@ -55,7 +55,8 @@ class EggApplication extends EggCore { this.messenger = new Messenger(); // dump config after ready, ensure all the modifications during start will be recorded - this.ready(() => this.dumpConfig()); + // make sure dumpConfig is the last ready callback + this.ready(() => process.nextTick(() => this.dumpConfig())); this._setupTimeoutTimer(); this.console.info('[egg:core] App root: %s', this.baseDir); diff --git a/test/fixtures/apps/demo/app.js b/test/fixtures/apps/demo/app.js new file mode 100644 index 0000000000..fd4ac86a91 --- /dev/null +++ b/test/fixtures/apps/demo/app.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = app => { + app.ready(() => { + app.config.tips = 'hello egg started'; + }); +}; diff --git a/test/fixtures/apps/demo/config/config.default.js b/test/fixtures/apps/demo/config/config.default.js index 084ff4ad9e..446cf4d7e6 100644 --- a/test/fixtures/apps/demo/config/config.default.js +++ b/test/fixtures/apps/demo/config/config.default.js @@ -18,3 +18,5 @@ exports.mysql = { consumerSecret: 'this is consumerSecret', someSecret: null, }; + +exports.tips = 'hello egg'; diff --git a/test/lib/egg.test.js b/test/lib/egg.test.js index e2a0809ab2..889065c8f9 100644 --- a/test/lib/egg.test.js +++ b/test/lib/egg.test.js @@ -25,8 +25,10 @@ describe('test/lib/egg.test.js', () => { let json = require(path.join(baseDir, 'run/agent_config.json')); assert(/\d+\.\d+\.\d+/.test(json.plugins.onerror.version)); assert(json.config.name === 'demo'); + assert(json.config.tips === 'hello egg'); json = require(path.join(baseDir, 'run/application_config.json')); assert(/\d+\.\d+\.\d+/.test(json.plugins.onerror.version)); + assert(json.config.tips === 'hello egg started'); }); it('should dump config meta', () => {