@devmoods/express-extras 0.18.1 → 0.19.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/dist/middleware.js +30 -1
- package/package.json +15 -15
package/dist/middleware.js
CHANGED
|
@@ -5,14 +5,18 @@ import cookieParser from 'cookie-parser';
|
|
|
5
5
|
import helmet from 'helmet';
|
|
6
6
|
import { withRequestContext } from './context.js';
|
|
7
7
|
import { NotFound } from './errors.js';
|
|
8
|
+
import { getLogger } from './logger.js';
|
|
8
9
|
export const urlencodedParser = bodyParser.urlencoded;
|
|
9
10
|
export const jsonParser = bodyParser.json;
|
|
11
|
+
const logger = getLogger('core');
|
|
10
12
|
export { asyncMiddleware as route };
|
|
11
13
|
/**
|
|
12
14
|
* Register middleware that must come before the app routes.
|
|
13
15
|
*/
|
|
14
16
|
export function before({ cookies = false, helmet: useHelmet = true, json: useJson = true, allowUnsafeInlineScripts = false, } = {}) {
|
|
15
17
|
return compose([
|
|
18
|
+
withRequestContext(),
|
|
19
|
+
logRequestDuration(),
|
|
16
20
|
Sentry.Handlers.requestHandler(),
|
|
17
21
|
Sentry.Handlers.tracingHandler(),
|
|
18
22
|
useHelmet &&
|
|
@@ -39,9 +43,34 @@ export function before({ cookies = false, helmet: useHelmet = true, json: useJso
|
|
|
39
43
|
}),
|
|
40
44
|
useJson && jsonParser(),
|
|
41
45
|
cookies && cookieParser(),
|
|
42
|
-
withRequestContext(),
|
|
43
46
|
].filter(Boolean));
|
|
44
47
|
}
|
|
48
|
+
function logRequestDuration() {
|
|
49
|
+
const getDurationInMilliseconds = (start) => {
|
|
50
|
+
const NS_PER_SEC = 1e9;
|
|
51
|
+
const NS_TO_MS = 1e6;
|
|
52
|
+
const diff = process.hrtime(start);
|
|
53
|
+
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
|
|
54
|
+
};
|
|
55
|
+
return (req, res, next) => {
|
|
56
|
+
const start = process.hrtime();
|
|
57
|
+
logger.info('http request', {
|
|
58
|
+
method: req.method,
|
|
59
|
+
url: req.originalUrl,
|
|
60
|
+
path: req.path,
|
|
61
|
+
});
|
|
62
|
+
res.on('finish', () => {
|
|
63
|
+
const duration = getDurationInMilliseconds(start);
|
|
64
|
+
logger.info('http response', {
|
|
65
|
+
method: req.method,
|
|
66
|
+
url: req.originalUrl,
|
|
67
|
+
path: req.path,
|
|
68
|
+
duration,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
next();
|
|
72
|
+
};
|
|
73
|
+
}
|
|
45
74
|
/**
|
|
46
75
|
* Middleware that sends a 404
|
|
47
76
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devmoods/express-extras",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Kubernetes-ready utilities for rapid Node.js application development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,32 +23,32 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@devmoods/eslint-config": "^1.
|
|
27
|
-
"@sentry/types": "^7.
|
|
26
|
+
"@devmoods/eslint-config": "^1.2.0",
|
|
27
|
+
"@sentry/types": "^7.60.1",
|
|
28
28
|
"@types/express-serve-static-core": "^4.17.35",
|
|
29
|
-
"@types/node": "20.
|
|
29
|
+
"@types/node": "20.4.5",
|
|
30
30
|
"@types/supertest": "2.0.12",
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
32
|
-
"@typescript-eslint/parser": "^
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
32
|
+
"@typescript-eslint/parser": "^6.2.0",
|
|
33
33
|
"chalk": "^5.3.0",
|
|
34
|
-
"eslint": "^8.
|
|
34
|
+
"eslint": "^8.46.0",
|
|
35
35
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
36
|
-
"eslint-plugin-prettier": "^
|
|
37
|
-
"eslint-plugin-react": "^7.
|
|
36
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
37
|
+
"eslint-plugin-react": "^7.33.1",
|
|
38
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
39
39
|
"import-sort-cli": "6.0.0",
|
|
40
40
|
"import-sort-style-module": "6.0.0",
|
|
41
41
|
"isomorphic-fetch": "3.0.0",
|
|
42
|
-
"prettier": "
|
|
42
|
+
"prettier": "3.0.0",
|
|
43
43
|
"supertest": "6.3.3",
|
|
44
44
|
"ts-node": "10.9.1",
|
|
45
45
|
"typescript": "5.1.6",
|
|
46
|
-
"vitest": "^0.
|
|
46
|
+
"vitest": "^0.33.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@devmoods/fetch": "^3.3.0",
|
|
50
50
|
"@godaddy/terminus": "^4.12.1",
|
|
51
|
-
"@sentry/node": "^7.
|
|
51
|
+
"@sentry/node": "^7.60.1",
|
|
52
52
|
"@types/bcrypt": "^5.0.0",
|
|
53
53
|
"@types/body-parser": "^1.19.2",
|
|
54
54
|
"@types/bunyan": "^1.8.8",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/cookie-parser": "^1.4.3",
|
|
57
57
|
"@types/express": "^4.17.17",
|
|
58
58
|
"@types/jsonwebtoken": "^9.0.2",
|
|
59
|
-
"@types/nodemailer": "^6.4.
|
|
59
|
+
"@types/nodemailer": "^6.4.9",
|
|
60
60
|
"@types/pg": "^8.10.2",
|
|
61
61
|
"@types/uuid": "^9.0.2",
|
|
62
62
|
"ajv": "^8.12.0",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"dotenv": "^16.3.1",
|
|
70
70
|
"express": "^4.18.2",
|
|
71
71
|
"helmet": "^7.0.0",
|
|
72
|
-
"jsonwebtoken": "^9.0.
|
|
72
|
+
"jsonwebtoken": "^9.0.1",
|
|
73
73
|
"meow": "^12.0.1",
|
|
74
|
-
"nodemailer": "^6.9.
|
|
74
|
+
"nodemailer": "^6.9.4",
|
|
75
75
|
"pg": "^8.11.1",
|
|
76
76
|
"redis": "^4.6.7",
|
|
77
77
|
"sql-template-strings": "^2.2.2",
|