From 142a38f9df2e284d30e19c9449a87fcd0ef61b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 24 Sep 2020 19:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=AA=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E;=E4=BC=98=E5=8C=96jwt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/index.js | 4 ++-- index.js | 9 +++++++-- lib/views.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 lib/views.js diff --git a/config/index.js b/config/index.js index 488cdfb..0adc582 100644 --- a/config/index.js +++ b/config/index.js @@ -13,7 +13,7 @@ export default { type: 'native', // native 或 redis ttl: 3600 * 24 * 7, domain: '', // NODESSID域, 默认等于domain - level: 0, // 校验级别, 0: 不校验客户端, 1: 校验UA, 2: 校验UA+IP + level: 0, // 校验级别, 0: 不校验客户端, 2: ua, 4: ip, 6: ua + ip db: { host: '127.0.0.1', port: 6379, @@ -38,7 +38,7 @@ export default { origin: [], // ['abc.com', 'a.foo.com'] maxAge: 0 }, - jwt: null, // jwt secret + jwt: false, // jwt opened regexp: { // 常用正则 email: /^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/, diff --git a/index.js b/index.js index da61f4c..10be550 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,8 @@ import Jwt from '@gm5/jwt' import config from './config/index.js' +import Views from './lib/views.js' + import routerWare from './middleware/router.js' import corsWare from './middleware/cors.js' @@ -42,12 +44,15 @@ export default class Five { session.domain = session.domain || domain this.set({ domain, session }) - // 安装jwt - this.install(Jwt) + // 用户没手动安装模板引擎时, 才会安装内置的伪引擎 + if (!this.$$views) { + this.install(Views) + } // 将session中间件提到最前 // 以便用户自定义的中间件可以直接操作session this.install(sessionStore) + this.install(Jwt) this.__MIDDLEWARE__.unshift(sessionWare) // 路由中间件要在最后 diff --git a/lib/views.js b/lib/views.js new file mode 100644 index 0000000..b37c4ca --- /dev/null +++ b/lib/views.js @@ -0,0 +1,29 @@ +/** + * 简单的模板渲染, 用于在不需要smarty这种重量级模板引擎的时候 + * 可以兼容smarty的api + * @author yutent + * @date 2020/09/24 16:41:31 + */ + +import fs from 'iofs' +import path from 'path' + +export default { + name: 'views', + install() { + // + var updir = this.get('VIEWS') + + return { + assign() { + // + }, + + render(file, noParse) { + var filePath = path.join(updir, file) + var buf = fs.cat(filePath) + return Promise.resolve(buf) + } + } + } +}