Register controllers from glob

This commit is contained in:
Adrian Obelmejias
2016-02-15 16:52:40 -05:00
parent f691bae41d
commit 6910b04e91
2 changed files with 11 additions and 7 deletions
+1
View File
@@ -25,6 +25,7 @@
"babel-preset-es2015": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"bcrypt": "^0.8.5",
"glob": "^7.0.0",
"jsonwebtoken": "^5.5.4",
"koa": "^2.0.0-alpha.3",
"koa-bodyparser": "^2.0.1",
+10 -7
View File
@@ -1,11 +1,14 @@
import users from './users'
import auth from './auth'
import { Glob } from 'glob'
exports = module.exports = function Controllers(app) {
app
.use(auth.routes())
.use(auth.allowedMethods())
new Glob(`${__dirname}/*.js`, { ignore: '**/index.js' }, (err, matches) => {
if (err) { throw err }
.use(users.routes())
.use(users.allowedMethods())
matches.forEach((file) => {
const controller = require(file).default
app
.use(controller.routes())
.use(controller.allowedMethods())
})
})
}