@rpcbase/server 0.46.0 → 0.49.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/database.js +49 -11
- package/express/index.js +0 -1
- package/mailer/index.js +2 -1
- package/package.json +6 -6
package/database.js
CHANGED
|
@@ -20,25 +20,63 @@ const mongo_url = `mongodb://${replicaset_str}/${DATABASE_NAME}`
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
module.exports = async() => {
|
|
23
|
-
console.log("mongo_url", mongo_url)
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
keepAliveInitialDelay: 5000,
|
|
29
|
-
minPoolSize: 3,
|
|
30
|
-
serverSelectionTimeoutMS: 5000,
|
|
31
|
-
family: 4, // force ipv4
|
|
24
|
+
// set listeners before attempting to connect
|
|
25
|
+
mongoose.connection.on("connected", () => {
|
|
26
|
+
console.log("mongoose connected")
|
|
32
27
|
})
|
|
33
28
|
|
|
34
29
|
mongoose.connection.on("disconnected", (arg) => {
|
|
35
30
|
console.log("Mongoose disconnected", arg)
|
|
36
31
|
})
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
// TODO: should we be retrying in dev only
|
|
34
|
+
mongoose.connection.on("error", (err) => {
|
|
35
|
+
console.log("Mongoose connection error", /*err*/)
|
|
36
|
+
// replicaSet has no primary, retry connecting in a moment
|
|
37
|
+
if (err.reason.type === "ReplicaSetNoPrimary") {
|
|
38
|
+
console.log("no primary, will retry")
|
|
39
|
+
setTimeout(async() => {
|
|
40
|
+
console.log("retrying now")
|
|
41
|
+
await mongoose.connect(mongo_url, connect_opts)
|
|
42
|
+
}, 3000)
|
|
43
|
+
} else {
|
|
44
|
+
console.log("WOW ici mongoose connection error", err)
|
|
45
|
+
}
|
|
40
46
|
})
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
|
|
49
|
+
console.log("mongo_url", mongo_url)
|
|
50
|
+
|
|
51
|
+
const connect_opts = {
|
|
52
|
+
replicaSet: "rs0",
|
|
53
|
+
keepAlive: true,
|
|
54
|
+
keepAliveInitialDelay: 5000,
|
|
55
|
+
minPoolSize: 3,
|
|
56
|
+
serverSelectionTimeoutMS: 5000,
|
|
57
|
+
heartbeatFrequencyMS: 1000,
|
|
58
|
+
family: 4, // force ipv4
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// INFO: on reconnects
|
|
62
|
+
// https://jira.mongodb.org/browse/NODE-834?focusedCommentId=1412582&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1412582
|
|
63
|
+
// The driver will fail on first connect if it cannot connect to the host. This is by design to ensure quick failure on unreachable hosts. Reconnect behavior only kicks in once the driver has performed the initial connect.
|
|
64
|
+
try {
|
|
65
|
+
await mongoose.connect(mongo_url, connect_opts)
|
|
66
|
+
} catch (err) {
|
|
67
|
+
// TODO: handle error ?
|
|
68
|
+
if (err.reason.type === "ReplicaSetNoPrimary") {
|
|
69
|
+
// console.log("no primary, will retry")
|
|
70
|
+
// setTimeout(async() => {
|
|
71
|
+
// console.log("retrying now")
|
|
72
|
+
// await mongoose.connect(mongo_url, connect_opts)
|
|
73
|
+
// }, 3000)
|
|
74
|
+
} else {
|
|
75
|
+
console.log("ICI SERVER GOT ERROR")
|
|
76
|
+
console.log(err)
|
|
77
|
+
console.log("JSON:", JSON.stringify(err, null, 2))
|
|
78
|
+
console.log("resaon", err.reason)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
43
81
|
|
|
44
82
|
}
|
package/express/index.js
CHANGED
package/mailer/index.js
CHANGED
|
@@ -12,7 +12,8 @@ if (is_production) {
|
|
|
12
12
|
} else {
|
|
13
13
|
client = {
|
|
14
14
|
sendEmail: async(payload) => {
|
|
15
|
-
console.log("sendEmail disabled outside of production"
|
|
15
|
+
console.log("sendEmail disabled outside of production")
|
|
16
|
+
console.log("From:", payload.From, "To:", payload.To, "Subject:", payload.Subject)
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"body-parser": "1.
|
|
13
|
+
"body-parser": "1.20.0",
|
|
14
14
|
"connect-redis": "6.1.3",
|
|
15
15
|
"cors": "2.8.5",
|
|
16
16
|
"debug": "4.3.4",
|
|
17
17
|
"dotenv": "16.0.0",
|
|
18
18
|
"express": "4.17.3",
|
|
19
19
|
"express-session": "1.17.2",
|
|
20
|
-
"glob": "
|
|
21
|
-
"mongoose": "6.
|
|
20
|
+
"glob": "8.0.1",
|
|
21
|
+
"mongoose": "6.3.1",
|
|
22
22
|
"postmark": "3.0.1",
|
|
23
|
-
"redis": "4.0.
|
|
23
|
+
"redis": "4.0.6",
|
|
24
24
|
"validator": "13.7.0",
|
|
25
|
-
"yargs": "17.4.
|
|
25
|
+
"yargs": "17.4.1"
|
|
26
26
|
}
|
|
27
27
|
}
|