Skip to content

Commit

Permalink
Changed express middleware to use keyword argument and added prefix arg
Browse files Browse the repository at this point in the history
I've decided to change the middleware to user keyword arguments
because the positional argument don't seem to be mutually exclusive.
I may want to specify the userId without specifying the `numPathComponents`.

Additionally, I've added a prefix argument that strips the req.url of
the specified prefix. This can be useful, if the REST url has something
like a version in the path.
  • Loading branch information
Jesse Vander Does committed Aug 29, 2014
1 parent 920e30d commit 6a6602e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,19 @@ Acl.prototype.clean = function(callback){
Express Middleware
*/
Acl.prototype.middleware = function(numPathComponents, userId, actions){
contract(arguments)
.params()
.params('number')
.params('number','string|number|function')
.params('number','string|number|function', 'string|array')
.end();

Acl.prototype.middleware = function(options){
// contract(arguments)
// .params()
// .params('number')
// .params('number','string|number|function')
// .params('number','string|number|function', 'string|array')
// .end();

var numPathComponents = options.numPathComponents;
var userId = options.userId;
var actions = options.actions;
var prefix = options.prefix;

var acl = this;

var HttpError = function(errorCode, msg){
Expand Down Expand Up @@ -513,6 +518,11 @@ Acl.prototype.middleware = function(numPathComponents, userId, actions){
}

url = req.url.split('?')[0];

if(prefix){
url = url.replace(prefix,'');
}

if(!numPathComponents){
resource = url;
}else{
Expand Down

0 comments on commit 6a6602e

Please sign in to comment.