@mimik/init 5.2.1 → 5.3.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/README.md +1 -1
- package/index.js +3 -2
- package/lib/route.js +29 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ The `return` object has the following strucuture:
|
|
|
34
34
|
```
|
|
35
35
|
For the preOps, postOps and exitOps the function are executed with 3 parameters (correlationId, config, server).
|
|
36
36
|
The following routes are reserved: `/healthcheck` and `/metrics`.
|
|
37
|
-
The base path is defined by taking the url property of the first item of the servers array in the api defintion file. Only relative url address will be handled (e.g. /mss/v1) and
|
|
37
|
+
The base path is defined by taking the url property of the first item of the servers array in the api defintion file. Only relative url address will be handled (e.g. /mss/v1) and templates in the url are not allowed.
|
|
38
38
|
|
|
39
39
|
| Param | Type | Description |
|
|
40
40
|
| --- | --- | --- |
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const { apiSetup, setupServerFiles } = require('@mimik/api-helper');
|
|
|
13
13
|
const { extractLogs } = require('./lib/logs');
|
|
14
14
|
const { sigProcess } = require('./lib/exit');
|
|
15
15
|
const { startHrTimeSet } = require('./lib/metrics');
|
|
16
|
-
const { healthCheckRoute, metricsRoute } = require('./lib/route');
|
|
16
|
+
const { healthCheckRoute, metricsRoute, bodyParserRoute } = require('./lib/route');
|
|
17
17
|
const {
|
|
18
18
|
HEALTHCHECK_ROUTE,
|
|
19
19
|
METRICS_ROUTE,
|
|
@@ -62,7 +62,7 @@ const {
|
|
|
62
62
|
* ```
|
|
63
63
|
* For the preOps, postOps and exitOps the function are executed with 3 parameters (correlationId, config, server).
|
|
64
64
|
* The following routes are reserved: `/healthcheck` and `/metrics`.
|
|
65
|
-
* The base path is defined by taking the url property of the first item of the servers array in the api defintion file. Only relative url address will be handled (e.g. /mss/v1) and
|
|
65
|
+
* The base path is defined by taking the url property of the first item of the servers array in the api defintion file. Only relative url address will be handled (e.g. /mss/v1) and templates in the url are not allowed.
|
|
66
66
|
*/
|
|
67
67
|
module.exports = (app, rootDir, config, validates, cluster, options) => {
|
|
68
68
|
const fatalError = (error, correlationId) => {
|
|
@@ -116,6 +116,7 @@ module.exports = (app, rootDir, config, validates, cluster, options) => {
|
|
|
116
116
|
sigProcess(SIGTERM, registration, options, config, server, unRegister, getCorrelationId(`system-shutdown(${SIGTERM}):${serverSettings.id}`));
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
app.use(bodyParserRoute());
|
|
119
120
|
app.use(helmet.contentSecurityPolicy({
|
|
120
121
|
directives: {
|
|
121
122
|
...helmet.contentSecurityPolicy.getDefaultDirectives(),
|
package/lib/route.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const http = require('http');
|
|
2
2
|
|
|
3
3
|
const { healthInfo } = require('@mimik/systeminfo');
|
|
4
|
+
const logger = require('@mimik/sumologic-winston-logger');
|
|
5
|
+
const { getCorrelationId, getUserAgent } = require('@mimik/request-helper');
|
|
6
|
+
const { publicIpFromRequest } = require('@mimik/address-helper');
|
|
4
7
|
|
|
5
8
|
const { CONTENT_TYPE, JSON_CONTENT } = require('./common');
|
|
6
9
|
|
|
@@ -25,7 +28,33 @@ const metricsRoute = (options) => (req, res) => options.metrics.register.metrics
|
|
|
25
28
|
res.end(JSON.stringify(errResponse), null, 2);
|
|
26
29
|
});
|
|
27
30
|
|
|
31
|
+
const bodyParserRoute = () => (err, req, res, next) => {
|
|
32
|
+
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
|
|
33
|
+
const { originalUrl } = req;
|
|
34
|
+
const method = req.method.toUpperCase();
|
|
35
|
+
const correlationId = getCorrelationId(req);
|
|
36
|
+
|
|
37
|
+
logger.warn(`Rejecting request with 400 for ${method} ${originalUrl}`, {
|
|
38
|
+
method,
|
|
39
|
+
path: originalUrl,
|
|
40
|
+
statusCode: 400,
|
|
41
|
+
userAgent: getUserAgent(req),
|
|
42
|
+
clientIP: publicIpFromRequest(req),
|
|
43
|
+
error: err,
|
|
44
|
+
}, correlationId);
|
|
45
|
+
if (correlationId) res.setHeader('x-correlation-id', correlationId);
|
|
46
|
+
return res.status(400).json({
|
|
47
|
+
statusCode: 400,
|
|
48
|
+
title: http.STATUS_CODES[400],
|
|
49
|
+
message: err.message,
|
|
50
|
+
error: err,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return next();
|
|
54
|
+
};
|
|
55
|
+
|
|
28
56
|
module.exports = {
|
|
29
57
|
healthCheckRoute,
|
|
30
58
|
metricsRoute,
|
|
59
|
+
bodyParserRoute,
|
|
31
60
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/init",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Init process for micro-service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@mimik/address-helper": "^1.6.10",
|
|
32
|
-
"@mimik/api-helper": "^1.0
|
|
32
|
+
"@mimik/api-helper": "^1.1.0",
|
|
33
33
|
"@mimik/healthcheck": "^1.5.11",
|
|
34
|
-
"@mimik/oauth-helper": "^3.0.
|
|
34
|
+
"@mimik/oauth-helper": "^3.0.2",
|
|
35
35
|
"@mimik/public-helper": "^2.0.1",
|
|
36
|
-
"@mimik/request-helper": "^1.7.
|
|
36
|
+
"@mimik/request-helper": "^1.7.11",
|
|
37
37
|
"@mimik/response-helper": "^3.1.0",
|
|
38
38
|
"@mimik/sumologic-winston-logger": "^1.6.21",
|
|
39
39
|
"@mimik/systeminfo": "^3.0.1",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"eslint-config-airbnb": "19.0.4",
|
|
49
49
|
"eslint-plugin-import": "2.29.1",
|
|
50
50
|
"eslint-plugin-jsx-a11y": "6.9.0",
|
|
51
|
-
"eslint-plugin-react": "7.
|
|
51
|
+
"eslint-plugin-react": "7.35.0",
|
|
52
52
|
"eslint-plugin-react-hooks": "4.6.2",
|
|
53
|
-
"husky": "9.
|
|
54
|
-
"jsdoc-to-markdown": "8.0.
|
|
53
|
+
"husky": "9.1.4",
|
|
54
|
+
"jsdoc-to-markdown": "8.0.3"
|
|
55
55
|
}
|
|
56
56
|
}
|