'use strict'; const path = require('path'); const fs = require('fs'); module.exports = function (app, router, opts) { fs.readdirSync(__dirname).forEach((filename) => { if (filename.indexOf('.') !== 0 && fs.lstatSync(path.join(__dirname, filename)).isDirectory()) { fs.readdirSync(path.join(__dirname, filename)).forEach((api) => { if (api.indexOf('.') == 0 || api.indexOf('.js') == -1) return; try { console.log(`加载路由文件 ${filename}/${api}`); require(`./${filename}/${api}`)(app, router, opts); } catch (error) { console.error(error); process.exit(-1); } }); } }); return router; };