From 4daf60ba90d45075e13da57fc97b20a155a7f0de Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 2 Nov 2023 17:10:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A8=A1=E5=BC=8F=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/index.js | 4 ++-- middleware/router.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/index.js b/config/index.js index f5b9dfd..2cdbc55 100644 --- a/config/index.js +++ b/config/index.js @@ -8,8 +8,8 @@ const ENV_PROD = 'production' const ENV_DEV = 'development' export default { - db: {}, - spa: false, // 单路由模式, 即无论是访问路径是什么, 永远只会调用 \apps\index\index() + // 动态路由模式, 即无论是访问路径是什么, 永远只会调用 \apps\index\index() + dynamic: false, port: 3000, env: process.env.NODE_ENV === ENV_PROD ? ENV_PROD : ENV_DEV, debug: process.env.NODE_ENV === ENV_DEV, // debug模式 diff --git a/middleware/router.js b/middleware/router.js index 37868f5..b97beb4 100644 --- a/middleware/router.js +++ b/middleware/router.js @@ -9,20 +9,20 @@ import { readonlyProp } from '../lib.js' export function createRouter() { return function (req, res, next) { let debug = this.get('debug') - let spa = this.get('spa') + let dynamic = this.get('dynamic') // 1. 先判断控制器是否存在 - if (!this.$load(spa ? 'index' : req.controller)) { + if (!this.$load(dynamic ? 'index' : req.controller)) { return res.error(`Controller [${req.controller}] not found`, 404) } // 2. 默认二级路由为index - if (req.path.length < 1 && spa === false) { + if (req.path.length < 1 && dynamic === false) { req.path.push('index') } // 3. 实例化控制器 - this.$load(spa ? 'index' : req.controller) + this.$load(dynamic ? 'index' : req.controller) .then(async ModuleController => { let ctrol, route, act let err = '' @@ -47,7 +47,7 @@ export function createRouter() { } } - if (spa) { + if (dynamic) { return ctrol.indexAction.apply(ctrol, req.path) } else { route = req.path.shift() diff --git a/package.json b/package.json index 233774a..1950e23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/core", - "version": "2.0.0", + "version": "2.0.1", "type": "module", "description": "Five.js, 一个轻量级的nodejs mvc框架 旨在简单易用, 5分钟即可上手", "author": "yutent ",