@rpcbase/server 0.31.0 → 0.34.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 +11 -5
- package/express/index.js +5 -4
- package/express/{session.js → session_middleware.js} +13 -15
- package/mongoose/index.js +0 -5
- package/package.json +1 -1
- package/mongoose/rts_delete_plugin.js +0 -12
package/database.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const mongoose = require("mongoose")
|
|
3
3
|
const validator = require("validator")
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const {DATABASE_NAME} = process.env
|
|
6
6
|
|
|
7
7
|
if (typeof DATABASE_PORT === "string" && !validator.isPort(DATABASE_PORT)) {
|
|
8
8
|
throw new Error("expected DATABASE_PORT to be a valid port number")
|
|
@@ -12,11 +12,17 @@ if (typeof DATABASE_NAME !== "string") {
|
|
|
12
12
|
throw new Error("expected DATABASE_NAME to be a string")
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const replicaset_str = [0, 1, 2].map((i) => `database${i}:${process.env["DATABASE_PORT_" + i]}`)
|
|
16
|
+
.join(",")
|
|
17
|
+
|
|
18
|
+
console.log("db connection str:", replicaset_str)
|
|
19
|
+
|
|
20
|
+
const mongo_url = `mongodb://${replicaset_str}/${DATABASE_NAME}?`
|
|
21
|
+
+ `replicaSet=rs0&readPreference=secondary`
|
|
16
22
|
|
|
17
23
|
module.exports = async() => {
|
|
18
|
-
console.log("
|
|
24
|
+
console.log("mongo_url", mongo_url)
|
|
19
25
|
const ret = await mongoose.connect(mongo_url)
|
|
20
|
-
|
|
21
|
-
//
|
|
26
|
+
console.log("waiting after return", ret)
|
|
27
|
+
// TODO: handle connection retry and pools
|
|
22
28
|
}
|
package/express/index.js
CHANGED
|
@@ -3,7 +3,7 @@ const cors = require("cors")
|
|
|
3
3
|
const express = require("express")
|
|
4
4
|
const body_parser = require("body-parser")
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const session_middleware = require("./session_middleware")
|
|
7
7
|
|
|
8
8
|
const is_production = process.env.IS_PRODUCTION === "yes"
|
|
9
9
|
const {APP_DOMAIN, CLIENT_PORT} = process.env
|
|
@@ -17,7 +17,6 @@ module.exports = () => {
|
|
|
17
17
|
|
|
18
18
|
app.disable("x-powered-by")
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
// tmp disable aggressive caching
|
|
22
21
|
app.set("etag", false)
|
|
23
22
|
|
|
@@ -42,14 +41,16 @@ module.exports = () => {
|
|
|
42
41
|
"http://localhost:8090",
|
|
43
42
|
"localhost",
|
|
44
43
|
]
|
|
45
|
-
console.log("SETUP CORS", cors_origins)
|
|
44
|
+
// console.log("SETUP CORS", cors_origins)
|
|
45
|
+
|
|
46
46
|
app.use(cors({
|
|
47
47
|
origin: cors_origins,
|
|
48
48
|
methods: ["GET", "POST"],
|
|
49
49
|
credentials: true // enable set-cookie
|
|
50
50
|
}))
|
|
51
51
|
|
|
52
|
-
session
|
|
52
|
+
console.log("use session middleware")
|
|
53
|
+
app.use(session_middleware)
|
|
53
54
|
|
|
54
55
|
app.get("/api/ping", (req, res) => res.json({status: "ok"}))
|
|
55
56
|
|
|
@@ -4,6 +4,7 @@ const redis = require("redis")
|
|
|
4
4
|
const validator = require("validator")
|
|
5
5
|
const redis_store = require("connect-redis")(session)
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
const {SESSION_STORE_PORT} = process.env
|
|
8
9
|
|
|
9
10
|
if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
|
|
@@ -12,20 +13,17 @@ if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PO
|
|
|
12
13
|
|
|
13
14
|
const session_store_url = `redis://session-store:${SESSION_STORE_PORT}`
|
|
14
15
|
|
|
16
|
+
const redis_client = redis.createClient({
|
|
17
|
+
url: session_store_url
|
|
18
|
+
})
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const session_middleware = session({
|
|
21
|
+
store: new redis_store({client: redis_client}),
|
|
22
|
+
proxy: true,
|
|
23
|
+
saveUninitialized: false,
|
|
24
|
+
// TODO: fix session secret
|
|
25
|
+
secret: "session secret wowow",
|
|
26
|
+
resave: false,
|
|
27
|
+
})
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
session({
|
|
23
|
-
store: new redis_store({client: redis_client}),
|
|
24
|
-
proxy: true,
|
|
25
|
-
saveUninitialized: false,
|
|
26
|
-
// TODO: fix session secret
|
|
27
|
-
secret: "session secret wowow",
|
|
28
|
-
resave: false,
|
|
29
|
-
})
|
|
30
|
-
)
|
|
31
|
-
}
|
|
29
|
+
module.exports = session_middleware
|
package/mongoose/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const mongoose = require("mongoose")
|
|
3
3
|
|
|
4
|
-
// browsers do not have mongoose plugins
|
|
5
|
-
if (typeof mongoose.plugin === "function") {
|
|
6
|
-
const rts_delete_plugin = require("./rts_delete_plugin")
|
|
7
|
-
mongoose.plugin(rts_delete_plugin)
|
|
8
|
-
}
|
|
9
4
|
|
|
10
5
|
module.exports = mongoose
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
// fixes the mongodb issue with missing fullDocument in change streams
|
|
4
|
-
// that is required for dispatching to proper sockets in real time state
|
|
5
|
-
|
|
6
|
-
module.exports = (schema, options) => {
|
|
7
|
-
console.log("MONGOOSE DELETE PLUGIN")
|
|
8
|
-
|
|
9
|
-
schema.post("remove", (arg, arg2) => {
|
|
10
|
-
console.log("DELETE WOWO", arg, arg2)
|
|
11
|
-
})
|
|
12
|
-
}
|