forked from lsongdev/koa-routeify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 820 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var fs = require('fs');
var path = require('path');
var parser = require('./parser');
var router = require('./router');
var debug = require('debug')('koa-routeify');
module.exports = function(app, options){
options = Object.assign({
routes : './routes/',
controllers : './controllers/'
}, options || {});
app.routes = [].concat.apply([], fs.readdirSync(path.resolve(options.routes))
.filter(function(file){
return /\.js$/.test(file);
}).map(function(file){
return parser(path.join(options.routes, file));
}));
debug(app.routes);
app.controllers = {};
app.routes.map(function(route){
app.controllers[ route.controller ] = require(
path.join(path.resolve(options.controllers), route.controller)
);
});
debug(app.controllers);
return router(app);
};