request.js
* @module greppy/app/worker/middleware/request
* @author Hermann Mayer <hermann.mayer92@gmail.com>
var RequestMiddleware = function(baseApp)
* Append the request middleware to the given application stack.
* @param {Object} app - Application to configure
* @param {function} callback - Function to call on finish
RequestMiddleware.prototype.configure = function(app, callback)
app.use(function greppyRequest(req, res, next) {
// Pre match the route of the request
// So we have to reconstruct the express router to
pass(req._route_index + 1, err);
req.route = route = app._router.matchRequest(req, i);
paramVal = key && req.params[key.name];
paramCallbacks = key && app._router.params[key.name];
} else if (paramCallbacks && undefined !== paramVal) {
var fn = paramCallbacks[paramIndex++];
if (err || !fn) return param(err);
fn(req, res, paramCallback, paramVal, key.name);
if (route && '/favicon.ico' !== req.url) {
self.baseApp.context.routes.some(function(contextRoute) {
if (req.method === contextRoute.method &&
route.path === contextRoute.path) {
req.greppy.route = contextRoute;
res.locals.controller = contextRoute.thisArg;
req.method.green.bold, req.url.cyan
req.greppy.route.controllerPath.red,
req.greppy.route.action.yellow
Object.keys(req.body).forEach(function(key) {
if (-1 !== key.indexOf('password')) {
requestLog += ' - Request data:\n' +
JSON.stringify(data, null, ' ').yellow;
// Write the full URL to the request
req.greppy.route.host = req.protocol + "://" + req.get('host');
req.greppy.route.url = req.greppy.route.host + req.url;