diff --git a/config/index.js b/config/index.js index 96f0101..4c7577e 100644 --- a/config/index.js +++ b/config/index.js @@ -40,6 +40,11 @@ export default { name: 'no-reply', passwd: '' }, + views: { + enabled: true, + dir: '', + ext: '.htm' + }, cors: { enabled: false, credentials: false, diff --git a/index.js b/index.js index 60eabb0..6e41bda 100644 --- a/index.js +++ b/index.js @@ -12,13 +12,12 @@ import fs from 'iofs' import Request from '@gm5/request' import Response from '@gm5/response' +import Views from '@gm5/views' import { sessionPackage, sessionConnect } from '@gm5/session' import { jwtPackage, jwtConnect } from '@gm5/jwt' import config from './config/index.js' -import Views from './lib/views.js' - import Routers from './middleware/router.js' import Cors from './middleware/cors.js' @@ -27,7 +26,7 @@ function hideProperty(host, name, value) { value: value, writable: true, enumerable: false, - configurable: true, + configurable: true }) } @@ -44,10 +43,8 @@ export default class Five { session.domain = session.domain || domain this.set({ domain, session }) - // 用户没手动安装模板引擎时, 才会安装内置的伪引擎 - if (!this.$$views) { - this.install(Views) - } + // 安装模板引擎 + this.install(Views) // 将jwt & session中间件提到最前 // 以便用户自定义的中间件可以直接操作session @@ -116,7 +113,7 @@ export default class Five { var list = fs.ls(dir) if (list) { - list.forEach((item) => { + list.forEach(item => { var { name } = path.parse(item) if (name.startsWith('.')) { return @@ -127,7 +124,7 @@ export default class Five { item = path.join(item, './index.js') } - this.__MODULES__[name] = import(item).catch((err) => { + this.__MODULES__[name] = import(item).catch(err => { return { default: null } }) }) @@ -143,7 +140,7 @@ export default class Five { this.__main__() - server = http.createServer(function (req, res) { + server = http.createServer(function(req, res) { var request = new Request(req, res) var response = new Response(req, res) @@ -158,7 +155,7 @@ export default class Five { if (fn) { ;(async function next() { - await fn.call(_this, request, response, function () { + await fn.call(_this, request, response, function() { fn = middleware.shift() if (fn) { next() diff --git a/lib/views.js b/lib/views.js deleted file mode 100644 index b37c4ca..0000000 --- a/lib/views.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 简单的模板渲染, 用于在不需要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) - } - } - } -} diff --git a/package.json b/package.json index b828002..e22db17 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@gm5/response": "^1.3.1", "@gm5/controller": "^1.0.0", "@gm5/jwt": "^1.1.0", + "@gm5/views": "^1.0.0", "crypto.js": "^2.0.2", "es.shim": "^2.0.1", "iofs": "^1.5.0"