优化路由;优化异常处理
parent
38ad516e08
commit
41e4f9de6d
15
index.js
15
index.js
|
@ -37,7 +37,7 @@ export default class Five {
|
||||||
constructor() {
|
constructor() {
|
||||||
hideProperty(this, '__FIVE__', Object.assign({}, init))
|
hideProperty(this, '__FIVE__', Object.assign({}, init))
|
||||||
hideProperty(this, '__MODULES__', {})
|
hideProperty(this, '__MODULES__', {})
|
||||||
hideProperty(this, '__MIDDLEWARE__', [])
|
hideProperty(this, '__MIDDLEWARE__', [credentialsWare])
|
||||||
}
|
}
|
||||||
|
|
||||||
__init__() {
|
__init__() {
|
||||||
|
@ -64,7 +64,7 @@ export default class Five {
|
||||||
// 将session和cookie的中间件提到最前
|
// 将session和cookie的中间件提到最前
|
||||||
// 以便用户自定义的中间件可以直接操作session和cookie
|
// 以便用户自定义的中间件可以直接操作session和cookie
|
||||||
// this.__MIDDLEWARE__.unshift(sessionWare)
|
// this.__MIDDLEWARE__.unshift(sessionWare)
|
||||||
this.__MIDDLEWARE__.unshift(credentialsWare)
|
// this.__MIDDLEWARE__.unshift(credentialsWare)
|
||||||
|
|
||||||
this.use(routerWare)
|
this.use(routerWare)
|
||||||
}
|
}
|
||||||
|
@ -148,13 +148,18 @@ export default class Five {
|
||||||
this.__init__()
|
this.__init__()
|
||||||
|
|
||||||
server = http.createServer(function(req, res) {
|
server = http.createServer(function(req, res) {
|
||||||
var response = new Response(req, res)
|
|
||||||
var request = new Request(req, res)
|
var request = new Request(req, res)
|
||||||
|
var response = new Response(req, res)
|
||||||
response.set('X-Powered-By', 'Five.js')
|
|
||||||
|
|
||||||
var middleware = _this.__MIDDLEWARE__.concat()
|
var middleware = _this.__MIDDLEWARE__.concat()
|
||||||
var fn = middleware.shift()
|
var fn = middleware.shift()
|
||||||
|
|
||||||
|
if (response.rendered) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.set('X-Powered-By', 'Five.js')
|
||||||
|
|
||||||
if (fn) {
|
if (fn) {
|
||||||
;(async function next() {
|
;(async function next() {
|
||||||
await fn.call(_this, request, response, function() {
|
await fn.call(_this, request, response, function() {
|
||||||
|
|
|
@ -24,8 +24,9 @@ export default function(req, res, next) {
|
||||||
// 3. 实例化控制器
|
// 3. 实例化控制器
|
||||||
this.__MODULES__[req.app]
|
this.__MODULES__[req.app]
|
||||||
.then(({ default: Mod }) => {
|
.then(({ default: Mod }) => {
|
||||||
var app,
|
var app
|
||||||
err = ''
|
var err = ''
|
||||||
|
|
||||||
if (Mod) {
|
if (Mod) {
|
||||||
app = new Mod({ ctx: this, req, res })
|
app = new Mod({ ctx: this, req, res })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue