yog2-kernel
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -11,2 +11,3 @@ 'use strict'; | ||
this.express = express; | ||
this.loader = loader; | ||
this.require = null; | ||
@@ -13,0 +14,0 @@ this.plugins = {}; |
{ | ||
"name": "yog2-kernel", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,12 +39,21 @@ var _ = require('lodash'); | ||
for (var i = 0; i < conf.middleware.length; i++) { | ||
var component = yog.plugins[conf.middleware[i]]; | ||
var middleware = conf.middleware[i]; | ||
// 如果是直接配置的中间件,则直接加载 | ||
if (typeof middleware === 'function'){ | ||
app.use(middleware); | ||
continue; | ||
} | ||
var component = yog.plugins[middleware]; | ||
var start = +(new Date()); | ||
if (MIDDLEWARE_DEBUG){ | ||
app.use(startTime(conf.middleware[i])); | ||
app.use(startTime(middleware)); | ||
} | ||
component && component(); | ||
if (!component){ | ||
throw new Error('middleware ' + middleware + ' not found'); | ||
} | ||
component(); | ||
if (MIDDLEWARE_DEBUG){ | ||
app.use(endTime(conf.middleware[i])); | ||
app.use(endTime(middleware)); | ||
} | ||
debuglog('middleware [%s] loaded in %d ms', conf.middleware[i], new Date() - start); | ||
debuglog('middleware [%s] loaded in %d ms', middleware, new Date() - start); | ||
} | ||
@@ -76,2 +85,6 @@ } | ||
tasks = _.remove(tasks, function(middleware){ | ||
return !_.isFunction(middleware); | ||
}); | ||
tasks.push(core); | ||
@@ -78,0 +91,0 @@ |
27126
725