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) + } + } + } +}