routers.js
811 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)) {
var stub=require(filePath);
var route;
for (route in stub) {
var func = procFunc(stub[route]);
console.log(route);
app.all(route, func);
}
}
});
}
function procFunc(proc) {
if (typeof proc === 'function') {
return proc;
} else {
return function(req, res) {
res.send(proc);
}
}
}