yog2-kernel
Advanced tools
Comparing version 0.2.6 to 0.2.7
{ | ||
"name": "yog2-kernel", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "yog2 kernel", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,3 @@ 'use strict'; | ||
function baseRouterHandler(req, res, next) { | ||
if (req.__auto_router_failed__ === true) { | ||
if (req.__autoRouterFailed__ === true) { | ||
next(); | ||
@@ -27,3 +27,4 @@ return; | ||
routerName = req.params.router; | ||
} else { | ||
} | ||
else { | ||
debuglog('trying to get default router [%s]', defaultRouter); | ||
@@ -33,3 +34,3 @@ routerName = defaultRouter; | ||
var router = getRouter(routerName); | ||
if (router === null) { | ||
if (router.__isNotFound__) { | ||
debuglog('router [%s] is missed, continue', routerName); | ||
@@ -57,3 +58,4 @@ next(); | ||
actionName = urlPath; | ||
} else { | ||
} | ||
else { | ||
debuglog('trying to get default action [%s]', defaultAction); | ||
@@ -65,3 +67,3 @@ actionName = defaultAction; | ||
debuglog('action [%s/%s] is missed, continue', routerName, actionName); | ||
req.__auto_router_failed__ = true; | ||
req.__autoRouterFailed__ = true; | ||
next(); | ||
@@ -100,5 +102,6 @@ return; | ||
routerPath = require.resolve(routerPath); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
routers[name] = null; | ||
return null; | ||
return createNotFoundAppRouter(); | ||
} | ||
@@ -148,3 +151,3 @@ var router = createActionRouter(name, routerPath); | ||
req.originalUrl, | ||
new Date() - req.__dispatcher_start_time__ | ||
new Date() - req.__dispatcherStartTime__ | ||
); | ||
@@ -161,11 +164,14 @@ | ||
}); | ||
} else { | ||
} | ||
else { | ||
debuglog('excute action [%s] with [%s] method action', action.__name__, req.method); | ||
verbAction(req, res, next); | ||
} | ||
} else { | ||
} | ||
else { | ||
if (typeof action === 'function') { | ||
debuglog('excute action [%s] with default action method', action.__name__); | ||
action(req, res, next); | ||
} else { | ||
} | ||
else { | ||
next(); | ||
@@ -178,3 +184,3 @@ } | ||
function createActionRouter(routerName, routerPath) { | ||
var router = express.Router(); | ||
var router = new express.Router(); | ||
@@ -207,3 +213,3 @@ // extend router | ||
baseRouter.use(function (req, res, next) { | ||
req.__dispatcher_start_time__ = +new Date(); | ||
req.__dispatcherStartTime__ = +new Date(); | ||
if (!isInjected) { | ||
@@ -221,2 +227,17 @@ rootRouterInjector(rootRouter); | ||
function createNotFoundAppRouter() { | ||
var router = new express.Router(); | ||
// action will go next directly | ||
router.action = function () { | ||
return function (req, res, next) { | ||
next(); | ||
}; | ||
}; | ||
router.__isNotFound__ = true; | ||
return router; | ||
} | ||
return { | ||
@@ -242,2 +263,2 @@ cleanCache: function () { | ||
}; | ||
}; | ||
}; |
var path = require('path'); | ||
var yog = require('yog2-kernel'); | ||
var debuglog = require('debuglog')('yog/recv-reload'); | ||
@@ -4,0 +3,0 @@ |
43382
1119