Skip to content

Commit

Permalink
fix: run dumpConfig at the last ready callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Nov 29, 2017
1 parent 50efe4c commit 76ff783
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/apps/demo/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = app => {
app.ready(() => {
app.config.tips = 'hello egg started';
});
};
2 changes: 2 additions & 0 deletions test/fixtures/apps/demo/config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ exports.mysql = {
consumerSecret: 'this is consumerSecret',
someSecret: null,
};

exports.tips = 'hello egg';
2 changes: 2 additions & 0 deletions test/lib/egg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 76ff783

Please sign in to comment.