增加伪模板引擎;优化jwt
parent
f468683a7d
commit
142a38f9df
|
@ -13,7 +13,7 @@ export default {
|
||||||
type: 'native', // native 或 redis
|
type: 'native', // native 或 redis
|
||||||
ttl: 3600 * 24 * 7,
|
ttl: 3600 * 24 * 7,
|
||||||
domain: '', // NODESSID域, 默认等于domain
|
domain: '', // NODESSID域, 默认等于domain
|
||||||
level: 0, // 校验级别, 0: 不校验客户端, 1: 校验UA, 2: 校验UA+IP
|
level: 0, // 校验级别, 0: 不校验客户端, 2: ua, 4: ip, 6: ua + ip
|
||||||
db: {
|
db: {
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
|
@ -38,7 +38,7 @@ export default {
|
||||||
origin: [], // ['abc.com', 'a.foo.com']
|
origin: [], // ['abc.com', 'a.foo.com']
|
||||||
maxAge: 0
|
maxAge: 0
|
||||||
},
|
},
|
||||||
jwt: null, // jwt secret
|
jwt: false, // jwt opened
|
||||||
regexp: {
|
regexp: {
|
||||||
// 常用正则
|
// 常用正则
|
||||||
email: /^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/,
|
email: /^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/,
|
||||||
|
|
9
index.js
9
index.js
|
@ -17,6 +17,8 @@ import Jwt from '@gm5/jwt'
|
||||||
|
|
||||||
import config from './config/index.js'
|
import config from './config/index.js'
|
||||||
|
|
||||||
|
import Views from './lib/views.js'
|
||||||
|
|
||||||
import routerWare from './middleware/router.js'
|
import routerWare from './middleware/router.js'
|
||||||
import corsWare from './middleware/cors.js'
|
import corsWare from './middleware/cors.js'
|
||||||
|
|
||||||
|
@ -42,12 +44,15 @@ export default class Five {
|
||||||
session.domain = session.domain || domain
|
session.domain = session.domain || domain
|
||||||
this.set({ domain, session })
|
this.set({ domain, session })
|
||||||
|
|
||||||
// 安装jwt
|
// 用户没手动安装模板引擎时, 才会安装内置的伪引擎
|
||||||
this.install(Jwt)
|
if (!this.$$views) {
|
||||||
|
this.install(Views)
|
||||||
|
}
|
||||||
|
|
||||||
// 将session中间件提到最前
|
// 将session中间件提到最前
|
||||||
// 以便用户自定义的中间件可以直接操作session
|
// 以便用户自定义的中间件可以直接操作session
|
||||||
this.install(sessionStore)
|
this.install(sessionStore)
|
||||||
|
this.install(Jwt)
|
||||||
this.__MIDDLEWARE__.unshift(sessionWare)
|
this.__MIDDLEWARE__.unshift(sessionWare)
|
||||||
|
|
||||||
// 路由中间件要在最后
|
// 路由中间件要在最后
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* 简单的模板渲染, 用于在不需要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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue