EggJS provides the feature of configuration
at project level
. EggBornJS extends the feature provided by EggJS, realizing the configuration
at the module level
- Module can specify its own
configuration
- The
configuration
atproject level
can override the one atmodule level
Definition of Config
src/suite-vendor/test-party/modules/test-party/backend/src/config/config.js
module.exports = appInfo => {
const config = {};
config.message = 'Hello World';
return config;
};
Usage of Config
Same Module
src/suite-vendor/test-party/modules/test-party/backend/src/controller/kitchen-sink/guide.js
async echo2() {
const message = this.ctx.config.message;
this.ctx.success(message);
}
Across Module
async echo2() {
const message = this.ctx.config.module('test-party').message;
this.ctx.success(message);
}
Name | Description |
---|---|
config.module(moduleName) | get the config of the specified module |
Override Config
Use project level
config to override module level
config, thereby changing Hello World
to Hello World!
src/backend/config/config.default.js
// modules
config.modules = {
'test-party': {
message: 'Hello World!',
},
};
Because EggJS can specify
config
separately fortest environment
,development environment
andproduction environment
, we can also customize the config of modules for different environments
Comments: