express-unless
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -7,5 +7,6 @@ var URL = require('url'); | ||
var opts = typeof options === 'function' ? {custom: options} : options; | ||
opts.useOriginalUrl = (typeof opts.useOriginalUrl === 'undefined') ? true : opts.useOriginalUrl; | ||
return function (req, res, next) { | ||
var url = URL.parse(req.originalUrl || req.url || '', true); | ||
var url = URL.parse((opts.useOriginalUrl ? req.originalUrl : req.url) || '', true); | ||
@@ -12,0 +13,0 @@ var skip = false; |
{ | ||
"name": "express-unless", | ||
"description": "Conditionally add a middleware to express with some common patterns.", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -9,5 +9,5 @@ "url": "git://github.com/jfromaniello/express-unless.git" | ||
"author": { | ||
"name": "José F. Romaniello", | ||
"email": "jfromaniello@gmail.com", | ||
"url": "http://joseoncode.com" | ||
"name": "José F. Romaniello", | ||
"email": "jfromaniello@gmail.com", | ||
"url": "http://joseoncode.com" | ||
}, | ||
@@ -21,4 +21,4 @@ "main": "index.js", | ||
"mocha": "~1.11.0", | ||
"chai": "~1.7.0" | ||
"chai": "~1.7.0" | ||
} | ||
} | ||
} |
@@ -29,3 +29,3 @@ Conditionally skip a middleware when a condition is met. | ||
mymid.unless = require('unless-express'); | ||
mymid.unless = require('express-unless'); | ||
@@ -42,2 +42,3 @@ return mymid; | ||
- `custom` it must be a function that accepts `req` and returns `true` / `false`. If the function returns true for the given request, ithe middleware will not run. | ||
- `useOriginalUrl` it should be `true` or `false`, default is `true`. if false, `path` will match against `req.url` instead of `req.originalUrl`. Please refer to [Express API](http://expressjs.com/4x/api.html#request) for the difference between `req.url` and `req.originalUrl`. | ||
@@ -44,0 +45,0 @@ |
@@ -64,2 +64,42 @@ var unless = require('../index'); | ||
describe('with PATH (useOriginalUrl) exception', function () { | ||
var mid = testMiddleware.unless({ | ||
path: ['/test', '/fobo'], | ||
useOriginalUrl: false | ||
}); | ||
it('should not call the middleware when one of the path match '+ | ||
'req.url instead of req.originalUrl', function () { | ||
var req = { | ||
originalUrl: '/orig/test?das=123', | ||
url: '/test?das=123' | ||
}; | ||
mid(req, {}, noop); | ||
assert.notOk(req.called); | ||
req = { | ||
originalUrl: '/orig/fobo?test=123', | ||
url: '/fobo?test=123' | ||
}; | ||
mid(req, {}, noop); | ||
assert.notOk(req.called); | ||
}); | ||
it('should call the middleware when the path doesnt match '+ | ||
'req.url even if path matches req.originalUrl', function () { | ||
var req = { | ||
originalUrl: '/test/test=123', | ||
url: '/foobar/test=123' | ||
}; | ||
mid(req, {}, noop); | ||
assert.ok(req.called); | ||
}); | ||
}); | ||
describe('with EXT exception', function () { | ||
@@ -66,0 +106,0 @@ var mid = testMiddleware.unless({ |
8231
169
64