routers.js
810 Bytes
/**
* 桩数据
* @author h1bomb
*/
var fs=require('fs');
var path=require('path');
module.exports = function(app) {
var configDir = path.join(__dirname, 'config');
var files = fs.readdirSync(configDir);
files.forEach(function (file) {
var filePath = path.join(configDir, file);
if (fs.statSync(filePath).isFile() && /.*\.js$/i.test(file)) {
console.log(filePath);
var stub=require(filePath);
var route;
for (route in stub) {
var func = procFunc(stub[route]);
app.all(route, func);
}
}
});
}
function procFunc(proc) {
if (typeof proc === 'function') {
return proc;
} else {
return function(req, res) {
res.send(proc);
}
}
}