Last active
August 29, 2015 14:02
-
-
Save undoZen/311d24f505d0adb5c25a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var routeProto = require('express/lib/router/route').prototype; | |
var routerProto = require('express/lib/router'); | |
var methods = require('express/node_modules/methods').concat(['all']); | |
wrapCallback = function (c) { | |
return c; | |
} | |
methods.forEach(function (method) { | |
var orig = routeProto[method]; | |
routeProto[method] = function () { | |
var callbacks = utils.flatten([].slice.call(arguments)); | |
return orig.apply(this, callbacks.map(wrapCallback)); | |
} | |
}); | |
(function () { | |
var cache = routerProto.use; | |
routerProto.use = function (route, fn) { | |
// default route to '/' | |
if ('string' != typeof route) { | |
fn = route; | |
route = '/'; | |
} | |
return cache.call(this, route, wrapCallback(fn)); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment