Merge branch 'xuebaoxin' of pplokijuhyg/blog-server into master
This commit is contained in:
commit
84679e3d59
@ -16,20 +16,22 @@ function addMapping(router, mapping) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addControllers(router,controllers_dir) {
|
function addControllers(router,controllers_dir) {
|
||||||
var files = fs.readdirSync(__dirname +"/"+ controllers_dir);
|
let dir = __dirname.replace("\\bin","")
|
||||||
|
|
||||||
|
var files = fs.readdirSync(dir +"/"+ controllers_dir);
|
||||||
var js_files = files.filter((f) => {
|
var js_files = files.filter((f) => {
|
||||||
return f.endsWith('.js');
|
return f.endsWith('.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var f of js_files) {
|
for (var f of js_files) {
|
||||||
console.log(`process controller: ${f}...`);
|
console.log(`process controller: ${f}...`);
|
||||||
let mapping = require(__dirname + `/${controllers_dir}/` + f);
|
let mapping = require(dir + `/${controllers_dir}/` + f);
|
||||||
addMapping(router, mapping);
|
addMapping(router, mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = function (dir) {
|
module.exports = function () {
|
||||||
let
|
let
|
||||||
controllers_dir = dir || 'controllers', // 如果不传参数,扫描目录默认为'controllers'
|
controllers_dir = 'controllers', // 如果不传参数,扫描目录默认为'controllers'
|
||||||
router = require('koa-router')();
|
router = require('koa-router')();
|
||||||
addControllers(router, controllers_dir);
|
addControllers(router, controllers_dir);
|
||||||
return router.routes();
|
return router.routes();
|
||||||
|
Loading…
Reference in New Issue
Block a user