@rpcbase/server 0.29.0 → 0.33.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 +9 -3
- package/express/index.js +5 -4
- package/express/{session.js → session_middleware.js} +13 -15
- package/mongoose/index.js +0 -3
- package/package.json +1 -1
- package/rpc/rpc_router.js +3 -2
- 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,10 +12,16 @@ 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("ICIII", )
|
|
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
26
|
// TODO: handle connection ret
|
|
21
27
|
// console.log(ret)
|
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
package/package.json
CHANGED
package/rpc/rpc_router.js
CHANGED
|
@@ -30,8 +30,9 @@ const rpc_router = (app) => {
|
|
|
30
30
|
const rpc_fn = require(module_path)
|
|
31
31
|
app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
|
|
32
32
|
// console.log("GOT REQ", req.body)
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// TODO: add jaegerclient / opentelemetry
|
|
34
|
+
const result = await rpc_fn(req.body, {req})
|
|
35
|
+
|
|
35
36
|
res.json(result)
|
|
36
37
|
}))
|
|
37
38
|
})
|
|
@@ -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
|
-
}
|