koahub-loader是基於 Koa平台Node.js開發的KoaHub.js的koahub-loader控制器,模型,幫助方法自動載入
koahub-loader
koahub-loader是基於 Koa平台Node.js開發的KoaHub.js的koahub-loader控制器,模型,幫助方法自動載入
koahub loader
Installation
$ npm install koahub-loader
Use with koa
// 1.model loader
var model = loader([
{
root: './app/model',
suffix: '.model.js'
},
{
root: './addon',
suffix: '.model.js',
filter: [/w*/model//]
}
]);
// 2.controller loader
var app = require('koa')();
var router = require('koa-router')();
var controller = loader([
{
root: './app/controller',
suffix: '.controller.js',
prefix: '/',
}, {
root: './addon',
suffix: '.controller.js',
prefix: '/addon/',
filter: [/w*/controller//]
}
]);
for (var key in controller) {
router.use(key, controller[key].routes());
}
app.use(router.routes());
// 3.util loader
var util = loader([
{
root: './app/common',
suffix: '.util.js'
},
{
root: './addon',
suffix: '.util.js',
filter: [/w*/common//]
}
]);
官網:http://js.koahub.com