Permalink
Browse files

[api] Attach extra objects to thisArg in http

  • Loading branch information...
pksunkara committed Feb 23, 2012
1 parent 550df71 commit 7a44fd3e828ea7c2776dee6e24db55e258e0d7a9
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/director/http/index.js
View
@@ -59,6 +59,15 @@ Router.prototype.on = function (method, path) {
director.Router.prototype.on.call(this, method, path, route);
};
+//
+// ### function attach (func)
+// ### @func {function} Function to execute on `this` before applying to router function
+// Ask the router to attach objects or manipulate `this` object on which the
+// function passed to the http router will get applied
+Router.prototype.attach = function (func) {
+ this._attach = func;
+};
+
//
// ### function dispatch (method, path)
// #### @req {http.ServerRequest} Incoming request to dispatch.
@@ -81,6 +90,10 @@ Router.prototype.dispatch = function (req, res, callback) {
stream,
error;
+ if (this._attach) {
+ this._attach.call(thisArg);
+ }
+
if (!fns || fns.length === 0) {
error = new exports.NotFound('Could not find path: ' + req.url)
if (callback) {

0 comments on commit 7a44fd3

Please sign in to comment.