egg-development-stub
v1.0.1
Published
stub service/proxy/... for egg development
Downloads
3
Maintainers
Readme
egg-development-stub
Stub class like service/grpc etc.. for develop purpose.
Install
$ npm i egg-development-stub --save-dev
Usage
// {app_root}/config/plugin.local.js
exports.stub = {
enable: true,
package: 'egg-development-stub',
};
Only use at not-production mode, will skip to
prod
. Recommand to hook atplugin.local.js
.
Configuration
Put your stub file at app/stub/{type}/**/*.js
.
egg-example
└── app
├── service
│ └── test.js
└── stub
└── service
└── test.js
Support stub service/grpc
by default, you can config mapping
to others.
// {app_root}/config/config.default.js
config.stub = {
// stub files root dir
// dir: path.join(appInfo.baseDir, 'stub'),
// stub target mapping
// mapping: {
// service: 'serviceClasses',
// grpc: 'grpcClasses',
// },
};
see config/config.default.js for more detail.
Example
Origin Service:
// app/service/test.js
module.exports = app => {
class TestService extends app.Service {
echo() {
return 'origin fn';
}
}
return TestService;
};
In general, you can stub with commonjs exports:
// app/stub/service/test.js
exports.echo = () => 'stub fn';
// or
module.exports = app => {
return {
echo: () => app.config.name;
}
}
Advanced usage: stub with sub class, so you can custom your logic.
// app/stub/service/test.js
module.exports = (app, TargetClass) => {
return StubClass extends TargetClass {
echo() {
return 'stub: ' + super.echo();
}
}
}
Note: SubClass mode don't support origin service use commonjs style.
Questions & Suggestions
Please open an issue here.