@contrast/route-coverage 1.4.0 → 1.5.0
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/lib/index.js +1 -0
- package/lib/install/koa.js +10 -19
- package/package.json +2 -2
package/lib/index.js
CHANGED
package/lib/install/koa.js
CHANGED
|
@@ -17,33 +17,24 @@
|
|
|
17
17
|
const { createSignature, patchType } = require('./../utils/route-info');
|
|
18
18
|
|
|
19
19
|
module.exports = function init(core) {
|
|
20
|
-
const { patcher, depHooks, routeCoverage
|
|
20
|
+
const { patcher, depHooks, routeCoverage } = core;
|
|
21
21
|
|
|
22
22
|
function emitRouteCoverage(url, method) {
|
|
23
23
|
const event = { signature: createSignature(url, method), url, method };
|
|
24
24
|
routeCoverage.discover(event);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
async function routeObservationMiddleware(ctx, next) {
|
|
32
|
-
const req = ctx.request;
|
|
27
|
+
const routeObservationPathClosure = ({ path }) =>
|
|
28
|
+
async function routeObservationMiddleware(ctx, next) {
|
|
29
|
+
const req = ctx.request;
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Arbitrary basename needed to parse out path
|
|
38
|
-
const parsedUrl = new URL(url, 'file://').pathname;
|
|
39
|
-
emitObservation(parsedUrl, method.toLowerCase());
|
|
40
|
-
} catch (err) {
|
|
41
|
-
logger.error({ err, url }, 'failed to parse route');
|
|
31
|
+
if (req) {
|
|
32
|
+
const { method } = req;
|
|
33
|
+
routeCoverage.observe({ url: path, method: method.toLowerCase() });
|
|
42
34
|
}
|
|
43
|
-
}
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
await next();
|
|
37
|
+
};
|
|
47
38
|
|
|
48
39
|
function registerRouteHandler(Router) {
|
|
49
40
|
patcher.patch(Router.prototype, 'register', {
|
|
@@ -63,7 +54,7 @@ module.exports = function init(core) {
|
|
|
63
54
|
});
|
|
64
55
|
}
|
|
65
56
|
|
|
66
|
-
layer.stack.unshift(
|
|
57
|
+
layer.stack.unshift(routeObservationPathClosure({ path }).bind(this));
|
|
67
58
|
}
|
|
68
59
|
});
|
|
69
60
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/route-coverage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"test": "../scripts/test.sh"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@contrast/common": "1.
|
|
17
|
+
"@contrast/common": "1.9.0"
|
|
18
18
|
}
|
|
19
19
|
}
|