express-unless
Advanced tools
Comparing version 0.5.0 to 1.0.0
@@ -12,3 +12,3 @@ var URL = require('url'); | ||
const result = function (req, res, next) { | ||
const result = async function (req, res, next) { | ||
var url = URL.parse((opts.useOriginalUrl ? req.originalUrl : req.url) || req.url || '', true); | ||
@@ -19,3 +19,3 @@ | ||
if (opts.custom) { | ||
skip = skip || opts.custom(req); | ||
skip = skip || (await opts.custom(req)); | ||
} | ||
@@ -22,0 +22,0 @@ |
{ | ||
"name": "express-unless", | ||
"description": "Conditionally add a middleware to express with some common patterns.", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -40,3 +40,3 @@ Conditionally skip a middleware when a condition is met. | ||
- `ext` it could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run. | ||
- `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. | ||
- `custom` it must be a function that accepts `req` and returns `true` / `false`. If the function returns true for the given request, the 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`. | ||
@@ -43,0 +43,0 @@ |
@@ -7,2 +7,3 @@ var unless = require('..'); | ||
req.called = true; | ||
next(); | ||
} | ||
@@ -242,4 +243,6 @@ | ||
describe('with custom exception', function () { | ||
var mid = testMiddleware.unless(function (req) { | ||
return req.baba; | ||
var mid = testMiddleware.unless({ | ||
custom: function (req) { | ||
return req.baba; | ||
} | ||
}); | ||
@@ -257,3 +260,3 @@ | ||
it('should call the middleware when the custom rule doesnt match', function () { | ||
it('should call the middleware when the custom rule doesnt match', function (done) { | ||
var req = { | ||
@@ -263,6 +266,39 @@ baba: false | ||
mid(req, {}, noop); | ||
mid(req, {}, () => { | ||
assert.ok(req.called); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
assert.ok(req.called); | ||
describe('with async custom exception', function () { | ||
var mid = testMiddleware.unless({ | ||
custom: async function (req) { | ||
return req.baba; | ||
} | ||
}); | ||
it('should not call the middleware when the async custom rule match', function (done) { | ||
var req = { | ||
baba: true | ||
}; | ||
mid(req, {}, () => { | ||
assert.notOk(req.called); | ||
done(); | ||
}); | ||
}); | ||
it('should call the middleware when the async custom rule doesnt match', function (done) { | ||
var req = { | ||
baba: false | ||
}; | ||
mid(req, {}, () => { | ||
assert.ok(req.called); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -269,0 +305,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13121
338
1
5