@rpcbase/server 0.346.0 → 0.348.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/express/index.js
CHANGED
|
@@ -30,13 +30,12 @@ const BODY_MAX_SIZE_MB = 80
|
|
|
30
30
|
|
|
31
31
|
log("server is production:", JSON.stringify(is_production))
|
|
32
32
|
|
|
33
|
-
module.exports =
|
|
33
|
+
module.exports = () => {
|
|
34
34
|
|
|
35
35
|
const app = express()
|
|
36
36
|
|
|
37
37
|
setup_handlers(app)
|
|
38
38
|
|
|
39
|
-
|
|
40
39
|
if (has_sentry && is_production) {
|
|
41
40
|
Sentry.init({
|
|
42
41
|
dsn: SENTRY_DSN,
|
|
@@ -77,12 +76,12 @@ module.exports = async() => {
|
|
|
77
76
|
|
|
78
77
|
custom_cors(app)
|
|
79
78
|
|
|
80
|
-
await sessions(app)
|
|
81
|
-
|
|
82
79
|
const pong_res = {app: `app_name:${JSON.stringify(process.env.RB_APP_NAME)}`, message: "pong"}
|
|
83
80
|
app.get("/__ping", (req, res) => res.json(pong_res))
|
|
84
81
|
app.post("/__ping", (req, res) => res.json(pong_res))
|
|
85
82
|
|
|
83
|
+
sessions(app)
|
|
84
|
+
|
|
86
85
|
auth(app)
|
|
87
86
|
api(app)
|
|
88
87
|
|
package/package.json
CHANGED
package/rts/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const debug = require("debug")
|
|
|
9
9
|
const colors = require("picocolors")
|
|
10
10
|
|
|
11
11
|
const mongoose = require("../mongoose")
|
|
12
|
-
const get_session_store_middleware = require("../src/sessions/get_session_store_middleware")
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
const log = debug("rb:rts:server")
|
|
@@ -296,9 +295,6 @@ const run_query = async(mongoose, socket_id, {model_name, query, query_key, opti
|
|
|
296
295
|
|
|
297
296
|
const data = await query_promise
|
|
298
297
|
|
|
299
|
-
// console.log("TMP Artificial delay")
|
|
300
|
-
// await Promise.delay(500)
|
|
301
|
-
|
|
302
298
|
const data_buf = JSON.stringify(data)
|
|
303
299
|
|
|
304
300
|
s.emit("query_payload", {model_name, query_key, data_buf})
|
|
@@ -321,7 +317,6 @@ const disconnect_handler = (socket_id, reason) => {
|
|
|
321
317
|
console.log("client disconnected, reason:", reason, "socket:", socket_id)
|
|
322
318
|
}
|
|
323
319
|
|
|
324
|
-
|
|
325
320
|
const local_queries = _socket_queries[socket_id] || {}
|
|
326
321
|
|
|
327
322
|
// remove all queries matching that socket id
|
|
@@ -383,7 +378,7 @@ const rts_server = async(server) => {
|
|
|
383
378
|
const has_session_store = process.env.RB_SESSION_STORE === "yes"
|
|
384
379
|
|
|
385
380
|
if (has_session_store) {
|
|
386
|
-
const session_store_middleware =
|
|
381
|
+
const session_store_middleware = require("../src/sessions/session_store_middleware")
|
|
387
382
|
// socket io session middleware
|
|
388
383
|
io.use((socket, next) => {
|
|
389
384
|
session_store_middleware(socket.request, {}, next)
|
package/src/sessions/index.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const pc = require("picocolors")
|
|
3
3
|
|
|
4
|
-
const get_session_store_middleware = require("./get_session_store_middleware")
|
|
5
|
-
|
|
6
4
|
|
|
7
5
|
const is_development = process.env.NODE_ENV === "development"
|
|
8
6
|
|
|
9
|
-
module.exports =
|
|
7
|
+
module.exports = (app) => {
|
|
10
8
|
const has_session_store = process.env.RB_SESSION_STORE === "yes"
|
|
11
9
|
|
|
12
10
|
if (has_session_store) {
|
|
13
11
|
console.log("using", pc.bold(pc.green("SESSION STORE")))
|
|
14
12
|
|
|
15
|
-
const session_store_middleware =
|
|
13
|
+
const session_store_middleware = require("./session_store_middleware")
|
|
16
14
|
app.use(session_store_middleware)
|
|
17
15
|
} else {
|
|
18
16
|
console.log("using", pc.bold(pc.red("REVERSE-PROXY SESSIONS!")), "if you want to use the session store, start with the --sessions argument")
|
|
@@ -9,13 +9,12 @@ const RedisStore = require("connect-redis").default
|
|
|
9
9
|
const is_docker = require("@rpcbase/std/is_docker")
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const {SESSION_STORE_PORT, APP_DOMAIN} = process.env
|
|
13
13
|
assert(SESSION_STORE_PORT, "SESSION_STORE_PORT is undefined")
|
|
14
14
|
|
|
15
|
-
const is_production = NODE_ENV === "production"
|
|
16
15
|
|
|
17
16
|
const log = debug("rb:session")
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
|
|
20
19
|
// WARNING:
|
|
21
20
|
// https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
|
|
@@ -29,12 +28,11 @@ const hostname = is_docker() ? "session-store" : "127.0.0.1"
|
|
|
29
28
|
|
|
30
29
|
console.log("session-store hostname", hostname, "port", SESSION_STORE_PORT)
|
|
31
30
|
|
|
31
|
+
let session_middleware = null
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
33
|
+
// EXTREME WARNING: docker issue
|
|
34
|
+
// when there is synchronous io redis client fails to connect
|
|
35
|
+
setTimeout(async() => {
|
|
38
36
|
const reconnectStrategy = (retries) => {
|
|
39
37
|
log("redis_client::reconnectStrategy::retrying with arg", retries)
|
|
40
38
|
if (retries < 5) {
|
|
@@ -67,7 +65,7 @@ const get_session_store_middleware = async() => {
|
|
|
67
65
|
proxy: true,
|
|
68
66
|
saveUninitialized: true,
|
|
69
67
|
// WARNING DO NOT USE IN PROD
|
|
70
|
-
secret: "
|
|
68
|
+
secret: "NOT_A_SECRET_BECAUSE_THIS_MIDDLEWARE_IS_NOT_MEANT_TO_BE_USED_IN_PROD",
|
|
71
69
|
resave: true,
|
|
72
70
|
cookie: {
|
|
73
71
|
// TODO: set to secure in production
|
|
@@ -81,16 +79,27 @@ const get_session_store_middleware = async() => {
|
|
|
81
79
|
// https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain
|
|
82
80
|
// TODO: WTF IS THIS
|
|
83
81
|
// if (is_docker() && typeof APP_DOMAIN === "string" && APP_DOMAIN.trim() !== "") {
|
|
82
|
+
// log("\n\n")
|
|
83
|
+
// log("\n\n")
|
|
84
84
|
// session_config.cookie.domain = APP_DOMAIN
|
|
85
85
|
// // session_config.cookie.secure = true
|
|
86
86
|
// session_config.cookie.sameSite = false
|
|
87
87
|
// }
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
session_middleware = session(session_config)
|
|
90
|
+
}, 200)
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
|
|
93
|
+
module.exports = (req, res, next) => {
|
|
94
|
+
if (typeof session_middleware === "function") {
|
|
92
95
|
session_middleware(req, res, next)
|
|
96
|
+
} else {
|
|
97
|
+
// recheck until it's a function and call it
|
|
98
|
+
const interval = setInterval(() => {
|
|
99
|
+
if (typeof session_middleware === "function") {
|
|
100
|
+
clearInterval(interval)
|
|
101
|
+
session_middleware(req, res, next)
|
|
102
|
+
}
|
|
103
|
+
}, 100)
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
module.exports = get_session_store_middleware
|