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 ",