Skip to content

Commit

Permalink
[api] Attach extra objects to thisArg in http
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Feb 23, 2012
1 parent 550df71 commit 7a44fd3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/director/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit 7a44fd3

Please sign in to comment.