common-rod 1.5.5 → 1.6.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/index.js +25 -3
- package/lib/http-service2.js +12 -3
- package/lib/rodSession.js +3 -0
- package/lib/validateConf.js +41 -10
- package/package.json +3 -3
- package/readme.md +42 -1
package/index.js
CHANGED
|
@@ -668,7 +668,29 @@ async function _connectMongodb(appRodSession, mongoConf){
|
|
|
668
668
|
|
|
669
669
|
let connectionString;
|
|
670
670
|
let strLog;
|
|
671
|
-
if(mongoConf.replicaSet){
|
|
671
|
+
// if(mongoConf.replicaSet){
|
|
672
|
+
// let hosts = "";
|
|
673
|
+
// for (let index = 0; index < mongoConf.hosts.length; index++) {
|
|
674
|
+
// const element = mongoConf.hosts[index];
|
|
675
|
+
// if(hosts !== "")hosts += ",";
|
|
676
|
+
|
|
677
|
+
// hosts += element.ip;
|
|
678
|
+
// if(element.port){
|
|
679
|
+
// hosts += ":"+element.port ;
|
|
680
|
+
// }else{
|
|
681
|
+
// hosts += ":27017";
|
|
682
|
+
// }
|
|
683
|
+
// }
|
|
684
|
+
// strLog = "host=" + hosts;
|
|
685
|
+
// connectionString = `mongodb://${auth}${hosts}/${mongoConf.db}`;
|
|
686
|
+
// }else{
|
|
687
|
+
// if(!mongoConf.port){
|
|
688
|
+
// mongoConf.port = "27017";
|
|
689
|
+
// }
|
|
690
|
+
// connectionString = `mongodb://${auth}${mongoConf.ip}:${mongoConf.port}/${mongoConf.db}`;
|
|
691
|
+
// strLog = `ip=${mongoConf.ip} port=${mongoConf.port}`;
|
|
692
|
+
// }
|
|
693
|
+
if( mongoConf.hosts !== undefined ){
|
|
672
694
|
let hosts = "";
|
|
673
695
|
for (let index = 0; index < mongoConf.hosts.length; index++) {
|
|
674
696
|
const element = mongoConf.hosts[index];
|
|
@@ -691,13 +713,13 @@ async function _connectMongodb(appRodSession, mongoConf){
|
|
|
691
713
|
strLog = `ip=${mongoConf.ip} port=${mongoConf.port}`;
|
|
692
714
|
}
|
|
693
715
|
|
|
694
|
-
|
|
695
716
|
let MongoClient = require('mongodb').MongoClient;
|
|
696
717
|
let opt = mongoConf.connection_string || {};
|
|
697
718
|
Object.assign( opt, {
|
|
698
719
|
useNewUrlParser: true,
|
|
699
720
|
useUnifiedTopology: true,
|
|
700
|
-
poolSize: 10
|
|
721
|
+
poolSize: 10,
|
|
722
|
+
serverSelectionTimeoutMS:10000 //timeout for driver connect to mongo
|
|
701
723
|
})
|
|
702
724
|
|
|
703
725
|
if(mongoConf.replicaSet){
|
package/lib/http-service2.js
CHANGED
|
@@ -46,11 +46,15 @@ function transformResponse(data) {
|
|
|
46
46
|
return data;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
// build fn, bind this
|
|
50
|
+
let defaultTransformResponse = [];
|
|
51
|
+
for (var i = 0; i < axios.defaults.transformResponse.length; i++) {
|
|
52
|
+
defaultTransformResponse.push(axios.defaults.transformResponse[i].bind(axios.defaults));
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
axios.interceptors.response.use(function (response) {
|
|
51
56
|
response.rawData = response.data;
|
|
52
57
|
for (var i = 0; i < defaultTransformResponse.length; i++) {
|
|
53
|
-
|
|
54
58
|
response.data = defaultTransformResponse[i](response.data);
|
|
55
59
|
}
|
|
56
60
|
return response;
|
|
@@ -305,7 +309,12 @@ async function handleError(rodSession, error, ins, optionAttribute) {
|
|
|
305
309
|
|
|
306
310
|
//response = 'TIMEOUT';
|
|
307
311
|
response = ERROR_TBL.TIMEOUT;
|
|
308
|
-
}else if(error.code === 'ENOTFOUND' ||
|
|
312
|
+
}else if(error.code === 'ENOTFOUND' ||
|
|
313
|
+
error.code === 'ECONNRESET' ||
|
|
314
|
+
error.code === 'ECONNREFUSED' ||
|
|
315
|
+
error.code === 'EAI_AGAIN' ||
|
|
316
|
+
error.code === 'ENETUNREACH'){
|
|
317
|
+
|
|
309
318
|
rodSession.debug('receive CONNECTION_ERROR from', optionAttribute.url);
|
|
310
319
|
rodSession.summary().addErrorBlock(optionAttribute._service, optionAttribute._command, 'ret=1', 'connection error');
|
|
311
320
|
rodSession.detail().addInputResponseError(optionAttribute._service, optionAttribute._command, optionAttribute._invoke);
|
package/lib/rodSession.js
CHANGED
package/lib/validateConf.js
CHANGED
|
@@ -52,7 +52,7 @@ function ipOrHost(obj, key, value){
|
|
|
52
52
|
}else{
|
|
53
53
|
//HOSTS
|
|
54
54
|
// let port = resolve(key.substring(0,key.lastIndexOf("."))+".port", obj);
|
|
55
|
-
console.log(9988899);
|
|
55
|
+
// console.log(9988899);
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -248,7 +248,13 @@ function validateConType(conn_type, path, obj, name){
|
|
|
248
248
|
"required_attr": false,
|
|
249
249
|
"required_val": false,
|
|
250
250
|
"type": "port"
|
|
251
|
-
},
|
|
251
|
+
}, {
|
|
252
|
+
"config_path": `${path}.replicaSet`,
|
|
253
|
+
"array": false,
|
|
254
|
+
"required_attr": false,
|
|
255
|
+
"required_val": true,
|
|
256
|
+
"type": "string"
|
|
257
|
+
}, {
|
|
252
258
|
"config_path": `${path}.db`,
|
|
253
259
|
"array": false,
|
|
254
260
|
"required_attr": true,
|
|
@@ -276,8 +282,39 @@ function validateConType(conn_type, path, obj, name){
|
|
|
276
282
|
]
|
|
277
283
|
};
|
|
278
284
|
|
|
279
|
-
let replicaSet = resolve(path+".replicaSet", obj);
|
|
280
|
-
if(replicaSet){
|
|
285
|
+
// let replicaSet = resolve(path+".replicaSet", obj);
|
|
286
|
+
// if(replicaSet){
|
|
287
|
+
// schemaForMongo.schema.splice(1,2); //delete ip / port
|
|
288
|
+
// schemaForMongo.schema.splice(1, 0, {
|
|
289
|
+
// "config_path": `${path}.hosts`,
|
|
290
|
+
// "array": true,
|
|
291
|
+
// "required_attr": true,
|
|
292
|
+
// "required_val": true,
|
|
293
|
+
// "type": "object",
|
|
294
|
+
// },{
|
|
295
|
+
// "config_path": `${path}.hosts[].ip`,
|
|
296
|
+
// "array": false,
|
|
297
|
+
// "required_attr": true,
|
|
298
|
+
// "required_val": true,
|
|
299
|
+
// "type": "condition",
|
|
300
|
+
// "condition" : validateIpOrSVC
|
|
301
|
+
// },{
|
|
302
|
+
// "config_path": `${path}.hosts[].port`,
|
|
303
|
+
// "array": false,
|
|
304
|
+
// "required_attr": false,
|
|
305
|
+
// "required_val": false,
|
|
306
|
+
// "type":"port"
|
|
307
|
+
// },{
|
|
308
|
+
// "config_path": `${path}.replicaSet`,
|
|
309
|
+
// "array": false,
|
|
310
|
+
// "required_attr": true,
|
|
311
|
+
// "required_val": true,
|
|
312
|
+
// "type":"string"
|
|
313
|
+
// });
|
|
314
|
+
// }
|
|
315
|
+
// schema.push(schemaForMongo);
|
|
316
|
+
let hosts = resolve(path+".hosts", obj);
|
|
317
|
+
if(hosts !== undefined){
|
|
281
318
|
schemaForMongo.schema.splice(1,2); //delete ip / port
|
|
282
319
|
schemaForMongo.schema.splice(1, 0, {
|
|
283
320
|
"config_path": `${path}.hosts`,
|
|
@@ -298,12 +335,6 @@ function validateConType(conn_type, path, obj, name){
|
|
|
298
335
|
"required_attr": false,
|
|
299
336
|
"required_val": false,
|
|
300
337
|
"type":"port"
|
|
301
|
-
},{
|
|
302
|
-
"config_path": `${path}.replicaSet`,
|
|
303
|
-
"array": false,
|
|
304
|
-
"required_attr": true,
|
|
305
|
-
"required_val": true,
|
|
306
|
-
"type":"string"
|
|
307
338
|
});
|
|
308
339
|
}
|
|
309
340
|
schema.push(schemaForMongo);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "common-rod",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "Thanakhan Iaocharoen",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"axios": "^0.21.
|
|
12
|
+
"axios": "^0.21.4",
|
|
13
13
|
"body-parser": "^1.19.0",
|
|
14
14
|
"cli-table": "^0.3.1",
|
|
15
15
|
"commonlog-kb": "^2.3.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"express": "^4.17.1",
|
|
20
20
|
"js-yaml": "^3.14.0",
|
|
21
21
|
"lodash": "^4.17.20",
|
|
22
|
-
"mongodb": "^3.
|
|
22
|
+
"mongodb": "^3.7.1",
|
|
23
23
|
"randomstring": "^1.1.5",
|
|
24
24
|
"swagger-ui-express": "^4.1.4"
|
|
25
25
|
}
|
package/readme.md
CHANGED
|
@@ -262,8 +262,49 @@ app.correlateQueue = function(req, res){
|
|
|
262
262
|
### Fixed
|
|
263
263
|
|
|
264
264
|
# [1.5.5] - 2021-08-01
|
|
265
|
+
```
|
|
265
266
|
Handle case PayloadTooLargeError(request body size bigger than pm2.commonRod.body_parser_limit)
|
|
266
267
|
Handle Throw error from module
|
|
268
|
+
```
|
|
269
|
+
### Added
|
|
270
|
+
### Changed
|
|
271
|
+
### Fixed
|
|
272
|
+
|
|
273
|
+
### Changed
|
|
274
|
+
### Fixed
|
|
275
|
+
|
|
276
|
+
# [1.5.6] - 2021-09-08
|
|
277
|
+
```
|
|
278
|
+
Handle case axios.defaults.transformResponse axios version 0.21.4
|
|
279
|
+
```
|
|
280
|
+
### Added
|
|
281
|
+
### Changed
|
|
282
|
+
### Fixed
|
|
283
|
+
|
|
284
|
+
# [1.5.7] - 2021-12-03
|
|
285
|
+
### Added
|
|
286
|
+
```
|
|
287
|
+
add mongo utils to get db
|
|
288
|
+
|
|
289
|
+
//example
|
|
290
|
+
let db = this.utils().mongo().getDb();
|
|
291
|
+
```
|
|
292
|
+
### Changed
|
|
293
|
+
### Fixed
|
|
294
|
+
|
|
295
|
+
# [1.6.0] - 2021-12-07
|
|
267
296
|
### Added
|
|
268
297
|
### Changed
|
|
269
|
-
|
|
298
|
+
```
|
|
299
|
+
change validator for mongo connection
|
|
300
|
+
allow config ip,port OR host[].ip, host[].port
|
|
301
|
+
```
|
|
302
|
+
### Fixed
|
|
303
|
+
|
|
304
|
+
# [1.6.1] - 2021-02-14
|
|
305
|
+
### Added
|
|
306
|
+
### Changed
|
|
307
|
+
### Fixed
|
|
308
|
+
```
|
|
309
|
+
add error code 'ENETUNREACH' to http request error
|
|
310
|
+
```
|