更新依赖

v1
宇天 2020-09-16 20:10:24 +08:00
parent 3d7963e6f5
commit b772d40fd8
13 changed files with 82 additions and 96 deletions

View File

@ -6,31 +6,30 @@
*/ */
import 'es.shim' // 加载拓展方法 import 'es.shim' // 加载拓展方法
import init from './lib/reg-init' import init from './lib/reg-init.js'
import http from 'http' import http from 'http'
import path from 'path' import path from 'path'
import Request from 'http.request' import Request from '../request/index.js'
import Response from 'http.response' import Response from '../response/index.js'
import Smarty from 'smartyx' //模板引擎 // import Smarty from 'smartyx' //模板引擎
import Log from './lib/module/log' //基础日志记录工具 import Log from './module/log.js' //基础日志记录工具
import Email from './lib/module/sendmail' //加载email发送类 import Email from './module/sendmail.js' //加载email发送类
import Mysql from 'mysqli' //加载mysql操作类 import Mysql from 'mysqli' //加载mysql操作类
import Ioredis from 'ioredis' import Ioredis from 'ioredis'
import sec from 'crypto.js' import sec from 'crypto.js'
import path from 'path'
import url from 'url' import url from 'url'
import fs from 'iofs' import fs from 'iofs'
import child from 'child_process' import child from 'child_process'
import Controller from './lib/controller' import Controller from './lib/controller.js'
import routerWare from './lib/middleware/router' import routerWare from './middleware/router.js'
import cookieWare from './lib/middleware/cookie' import cookieWare from './middleware/cookie.js'
import sessionWare from './lib/middleware/session' import sessionWare from './middleware/session.js'
import credentialsWare from './lib/middleware/credentials' import credentialsWare from './middleware/credentials.js'
var log = console.log var log = console.log
@ -49,22 +48,6 @@ export default class Five {
hideProperty(this, '__MODULES__', { __error__: null }) hideProperty(this, '__MODULES__', { __error__: null })
hideProperty(this, '__MIDDLEWARE__', []) hideProperty(this, '__MIDDLEWARE__', [])
hideProperty(this, '__INSTANCE__', {}) hideProperty(this, '__INSTANCE__', {})
global.libs = {
Smarty, //模板引擎
Log, //基础日志记录工具
Email, //加载email发送类
Mysql, //加载mysql操作类
Ioredis
}
global.Util = {
sec,
path,
url,
fs,
child
}
global.Controller = Controller
} }
__init__() { __init__() {
@ -147,7 +130,7 @@ export default class Five {
} }
// 预加载应用 // 预加载应用
preload(dir) { preload(dir) {
var list = Util.fs.ls(dir) var list = fs.ls(dir)
if (list) { if (list) {
list.forEach(file => { list.forEach(file => {

View File

@ -5,10 +5,11 @@
* *
*/ */
'use strict' import Smarty from 'smartyx' //模板引擎
const smarty = new libs.Smarty() import { sign, verify } from '../module/jwt.js'
const jwt = require('./module/jwt')
const smarty = new Smarty()
export default class Controller { export default class Controller {
constructor({ ctx, req, res }) { constructor({ ctx, req, res }) {
@ -18,8 +19,8 @@ export default class Controller {
this.response = res this.response = res
this.jwt = { this.jwt = {
sign: jwt.sign.bind(this), sign: sign.bind(this),
result: jwt.verify.call(this) result: verify.call(this)
} }
smarty.config('path', this.ctx.get('VIEWS')) smarty.config('path', this.ctx.get('VIEWS'))

View File

@ -1,53 +0,0 @@
/**
* 路由
* @authors yutent (yutent@doui.cc)
* @date 2015-10-01 19:11:19
*
*/
'use strict'
export default function(req, res, next) {
if (!this.__MODULES__[req.app]) {
if (!this.__MODULES__.__error__) {
res.error(`The app [${req.app}] not found`, 404)
} else {
res.error(
this.get('debug')
? this.__MODULES__.__error__.stack
: this.__MODULES__.__error__,
500
)
}
return
}
try {
if (req.path.length < 1) {
req.path.push('index')
}
var app = new this.__MODULES__[req.app]({ ctx: this, req, res })
if (this.get('routeMode') === 1) {
var act = req.path.shift()
if (app[act + 'Action']) {
app[act + 'Action'].apply(app, req.path).catch(err => {
res.error(this.get('debug') ? err.stack || err : err, 500)
})
} else {
res.error(`Action[${act}] not found`, 404)
}
} else {
if (app.indexAction) {
app.indexAction.apply(app, req.path).catch(err => {
res.error(this.get('debug') ? err.stack || err : err, 500)
})
} else {
res.error(`Default Action not found`, 404)
}
}
} catch (err) {
res.error(this.get('debug') ? err.stack || err : err, 500)
}
}

55
middleware/router.js Normal file
View File

@ -0,0 +1,55 @@
/**
* 路由
* @authors yutent (yutent@doui.cc)
* @date 2015-10-01 19:11:19
*
*/
'use strict'
export default function(req, res, next) {
if (!this.__MODULES__[req.app]) {
if (!this.__MODULES__.__error__) {
res.error(`The app [${req.app}] not found`, 404)
} else {
res.error(
this.get('debug')
? this.__MODULES__.__error__.stack
: this.__MODULES__.__error__,
500
)
}
return
}
try {
if (req.path.length < 1) {
req.path.push('index')
}
this.__MODULES__[req.app].then(Mod => {
var app = new Mod({ ctx: this, req, res })
if (this.get('routeMode') === 1) {
var act = req.path.shift()
if (app[act + 'Action']) {
app[act + 'Action'].apply(app, req.path).catch(err => {
res.error(this.get('debug') ? err.stack || err : err, 500)
})
} else {
res.error(`Action[${act}] not found`, 404)
}
} else {
if (app.indexAction) {
app.indexAction.apply(app, req.path).catch(err => {
res.error(this.get('debug') ? err.stack || err : err, 500)
})
} else {
res.error(`Default Action not found`, 404)
}
}
})
} catch (err) {
res.error(this.get('debug') ? err.stack || err : err, 500)
}
}

View File

@ -4,8 +4,8 @@
* @date 2018-07-26 15:50:25 * @date 2018-07-26 15:50:25
* @version $Id$ * @version $Id$
*/ */
import redisStore from '../module/redis-store' import redisStore from '../module/redis-store.js'
import nativeStore from '../module/native-store' import nativeStore from '../module/native-store.js'
export default function(req, res, next) { export default function(req, res, next) {
var opt = this.get('session') var opt = this.get('session')

View File

@ -6,7 +6,8 @@
*/ */
'use strict' 'use strict'
const mailx = require('mailx') import mailx from 'mailx'
export default class Sendmail { export default class Sendmail {
constructor({ host, port, mail, passwd } = {}) { constructor({ host, port, mail, passwd } = {}) {
if (!host || !port || !mail || !passwd) { if (!host || !port || !mail || !passwd) {

View File

@ -1,5 +1,5 @@
{ {
"name": "node-five", "name": "@gm5/core",
"version": "3.2.6", "version": "3.2.6",
"type": "module", "type": "module",
"description": "Five.js, 一个轻量级的nodejs mvc框架 旨在简单易用, 5分钟即可上手", "description": "Five.js, 一个轻量级的nodejs mvc框架 旨在简单易用, 5分钟即可上手",
@ -10,12 +10,11 @@
"@bytedo/es.shim": "^1.0.0", "@bytedo/es.shim": "^1.0.0",
"iofs": "^1.3.2", "iofs": "^1.3.2",
"mysqli": "^3.0.11", "mysqli": "^3.0.11",
"http.request": "^1.1.0", "@gm5/request": "^1.0.0",
"http.response": "^1.0.2", "@gm5/response": "^1.0.0",
"http.cookie": "^1.0.2", "@gm5/cookie": "^1.0.0",
"smartyx": "^1.3.1", "smartyx": "^1.3.1",
"ioredis": "^3.2.2", "ioredis": "^3.2.2"
"mailx": "^0.0.11"
}, },
"devDependencies": {}, "devDependencies": {},
"repository": { "repository": {