From c3ab472334f77ee732abb6b7d30d06c036c91748 Mon Sep 17 00:00:00 2001 From: pplokijuhyg <1162963624@qq.com> Date: Tue, 12 Nov 2019 16:45:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=8D=A2=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=B9=8B=E5=90=8E=E8=B7=AF=E7=94=B1=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/router.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/router.js b/bin/router.js index f3dcb54..f792b83 100644 --- a/bin/router.js +++ b/bin/router.js @@ -16,20 +16,22 @@ function addMapping(router, mapping) { } 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) => { return f.endsWith('.js'); }); for (var f of js_files) { console.log(`process controller: ${f}...`); - let mapping = require(__dirname + `/${controllers_dir}/` + f); + let mapping = require(dir + `/${controllers_dir}/` + f); addMapping(router, mapping); } } -module.exports = function (dir) { +module.exports = function () { let - controllers_dir = dir || 'controllers', // 如果不传参数,扫描目录默认为'controllers' + controllers_dir = 'controllers', // 如果不传参数,扫描目录默认为'controllers' router = require('koa-router')(); addControllers(router, controllers_dir); return router.routes(); -- 2.39.5