Skip to content

Commit

Permalink
add a built-in default implementation for connect-middleware
Browse files Browse the repository at this point in the history
lets not ask everybody to copy-paste this middleware.
lets user-code customise the augmented attribute name
  • Loading branch information
osherx authored and pbojinov committed Jan 27, 2016
1 parent e7151cd commit e0b44ee
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ function getClientIp(req) {
return ipAddress;
}

/**
* Expose a default implemtation for a connect middleware
*
* @options.attributeName - name of attribute to augment request object with
*/
getClientIp.mw = function(options) {
var attr = options.attributeName || "clientIp";
return function(req, res, next) {
req[attr] = requestIp.getClientIp(req); // on localhost > 127.0.0.1
next();
}
};

/**
* Expose mode public functions
*/
Expand Down

0 comments on commit e0b44ee

Please sign in to comment.