1.0.2 • Published 7 years ago
bifroster-framework-koa-loader v1.0.2
Koa framework
基于Koa的应用架构。
Install
npm install --save bifroster-framework-koa-loader
Usage
app.js
module.exports = require('bifroster-framework-koa-loader').bootstrap({
service: {
directory: 'service',
match: ['**/*.js'],
ignore: null,
override: true
},
constroller: {
directory: 'service',
match: ['**/*.js'],
ignore: null,
override: true
},
middleware: {
directory: 'service',
match: ['**/*.js'],
ignore: null,
override: true
},
router: 'router'
});
Service Controller and Middleware Layer Usage
app/service/index-test-value.js
const { Service } = require('bifroster-framework-koa-loader');
module.exports = class testService extends Service {
constructor(app) {
super(app);
}
value() {
return 2;
}
}
Invoke:
app.Service.indexTestValue;
app.Service.indexTestValue.value(); // 2
Router auto layer
app/router/index.js
:
module.exports = (app,router) => {
router.get('/', app.Controller.indexControllerTest.hello);
}
app/router/test.js
:
module.exports = (app, router) => {
router.get('/', app.Controller.indexControllerTest.hello);
router.get('/:id(\\d+)/user', app.Controller.indexControllerTest.b);
}
系统自动根据目录结构生成路由嵌套逻辑。
性能
所有执行都是服务启动前所做的,所以性能方面与一般KOA性能相同。不需要担心性能问题。