koa-helmet 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +1 -0
- package/lib/koa-helmet.js +1 -1
- package/lib/promisify.js +24 -0
- package/package.json +8 -8
- package/test/promisify.spec.js +38 -0
package/.travis.yml
CHANGED
package/lib/koa-helmet.js
CHANGED
package/lib/promisify.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes an express-style middleware and returns a promise-based version (returning a Promise,
|
|
5
|
+
* rather than calling the final argument as a callback) suitable for use with koa.
|
|
6
|
+
*
|
|
7
|
+
* @param {Function} middleware - The middleware to promisify
|
|
8
|
+
* @returns {Function} - The middleware function updated to return a Promise, not call a callback
|
|
9
|
+
*/
|
|
10
|
+
function koaHelmetPromisify (middleware) {
|
|
11
|
+
return function (req, res) {
|
|
12
|
+
return new Promise(function (resolve, reject) {
|
|
13
|
+
middleware(req, res, function (err) {
|
|
14
|
+
if (err) {
|
|
15
|
+
return reject(err);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return resolve();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = koaHelmetPromisify;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Matt Venables <mattvenables@gmail.com>",
|
|
4
4
|
"description": "Security header middleware collection for koa",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "4.2.
|
|
6
|
+
"version": "4.2.1",
|
|
7
7
|
"main": "lib/koa-helmet.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"format": "eslint lib test --fix",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"url": "git://github.com/venables/koa-helmet.git"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
26
|
+
"node": ">= 6.0.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"helmet": "^3.
|
|
29
|
+
"helmet": "^3.15.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"ava": "^
|
|
32
|
+
"ava": "^1.3.1",
|
|
33
33
|
"coveralls": "^3.0.3",
|
|
34
|
-
"eslint": "^5.
|
|
35
|
-
"eslint-plugin-node": "^
|
|
34
|
+
"eslint": "^5.15.1",
|
|
35
|
+
"eslint-plugin-node": "^8.0.1",
|
|
36
36
|
"koa": "^2.7.0",
|
|
37
|
-
"nyc": "^
|
|
38
|
-
"supertest": "^4.0.
|
|
37
|
+
"nyc": "^13.3.0",
|
|
38
|
+
"supertest": "^4.0.0"
|
|
39
39
|
},
|
|
40
40
|
"nyc": {
|
|
41
41
|
"reporter": [
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const promisify = require('../lib/promisify');
|
|
4
|
+
const test = require('ava');
|
|
5
|
+
|
|
6
|
+
function passingMiddleware (req, res, next) {
|
|
7
|
+
return next();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function failingMiddleware (req, res, next) {
|
|
11
|
+
return next(new Error('Expected Failure'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('returns a promisified version of the middleware which resolves the Promise on success', t => {
|
|
15
|
+
let middleware = promisify(passingMiddleware);
|
|
16
|
+
|
|
17
|
+
return middleware().then(
|
|
18
|
+
() => {
|
|
19
|
+
t.pass();
|
|
20
|
+
},
|
|
21
|
+
err => {
|
|
22
|
+
t.fail(err);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('returns a promisified version of the middleware which rejects the Promise on failure', t => {
|
|
28
|
+
let middleware = promisify(failingMiddleware);
|
|
29
|
+
|
|
30
|
+
return middleware().then(
|
|
31
|
+
() => {
|
|
32
|
+
t.fail('Unexpected Success!');
|
|
33
|
+
},
|
|
34
|
+
() => {
|
|
35
|
+
t.pass();
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|