完成模板引擎的安装
parent
6aca3e2695
commit
e6af5e6b1f
|
@ -40,6 +40,11 @@ export default {
|
|||
name: 'no-reply',
|
||||
passwd: ''
|
||||
},
|
||||
views: {
|
||||
enabled: true,
|
||||
dir: '',
|
||||
ext: '.htm'
|
||||
},
|
||||
cors: {
|
||||
enabled: false,
|
||||
credentials: false,
|
||||
|
|
13
index.js
13
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)
|
||||
}
|
||||
|
||||
// 将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 }
|
||||
})
|
||||
})
|
||||
|
|
29
lib/views.js
29
lib/views.js
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* 简单的模板渲染, 用于在不需要smarty这种重量级模板引擎的时候
|
||||
* 可以兼容smarty的api
|
||||
* @author yutent<yutent.io@gmail.com>
|
||||
* @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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue