yog2-kernel
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "yog2-kernel", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "yog2 kernel", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -186,5 +186,12 @@ 'use strict'; | ||
function createBaseRouter() { | ||
var baseRouter = express.Router(); | ||
var rootRouter = new express.Router(); | ||
var rootRouterInjector = null; | ||
function createBaseRouter(injector) { | ||
var baseRouter = new express.Router(); | ||
rootRouterInjector = injector; | ||
rootRouterInjector(rootRouter); | ||
baseRouter.use(function (req, res, next) { | ||
rootRouter(req, res, next); | ||
}); | ||
baseRouter.all('/:router*', baseRouterHandler); | ||
@@ -200,4 +207,7 @@ baseRouter.all('*', baseRouterHandler); | ||
actions = {}; | ||
// update root router | ||
rootRouter = new express.Router(); | ||
rootRouterInjector(rootRouter); | ||
}, | ||
middleware: createBaseRouter(), | ||
middleware: createBaseRouter, | ||
router: getRouter, | ||
@@ -204,0 +214,0 @@ action: function (name) { |
@@ -6,13 +6,9 @@ 'use strict'; | ||
module.exports.dispatcher = function(app, conf){ | ||
module.exports.dispatcher = function (app, conf) { | ||
conf.appPath = conf.appPath || yog.ROOT_PATH + '/app'; | ||
var dispatcherIns = new dispatcher(conf); | ||
//用户自定义rootRouter | ||
var rootRouter = new express.Router(); | ||
yog.dispatcher = dispatcherIns; | ||
conf.rootRouter(rootRouter); | ||
//自动路由 | ||
var autoRouter = dispatcherIns.middleware; | ||
return function(){ | ||
app.use(rootRouter); | ||
var autoRouter = dispatcherIns.middleware(conf.rootRouter); | ||
return function () { | ||
app.use(autoRouter); | ||
@@ -23,5 +19,5 @@ }; | ||
module.exports.dispatcher.defaultConf = { | ||
rootRouter: function(router){ | ||
rootRouter: function (router) { | ||
} | ||
}; |
33791
863