@rpcbase/server 0.344.0 → 0.346.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,7 +30,7 @@ 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 = async() => {
34
34
 
35
35
  const app = express()
36
36
 
@@ -77,7 +77,7 @@ module.exports = () => {
77
77
 
78
78
  custom_cors(app)
79
79
 
80
- sessions(app)
80
+ await sessions(app)
81
81
 
82
82
  const pong_res = {app: `app_name:${JSON.stringify(process.env.RB_APP_NAME)}`, message: "pong"}
83
83
  app.get("/__ping", (req, res) => res.json(pong_res))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.344.0",
3
+ "version": "0.346.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "scripts": {
package/rts/index.js CHANGED
@@ -9,6 +9,7 @@ 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")
12
13
 
13
14
 
14
15
  const log = debug("rb:rts:server")
@@ -359,7 +360,7 @@ const disconnect_handler = (socket_id, reason) => {
359
360
  }
360
361
 
361
362
 
362
- const rts_server = (server) => {
363
+ const rts_server = async(server) => {
363
364
  // register the delete plugin
364
365
  mongoose.plugin(mongoose_delete_plugin)
365
366
  // txn plugin
@@ -382,7 +383,7 @@ const rts_server = (server) => {
382
383
  const has_session_store = process.env.RB_SESSION_STORE === "yes"
383
384
 
384
385
  if (has_session_store) {
385
- const session_store_middleware = require("../src/sessions/session_store_middleware")
386
+ const session_store_middleware = await get_session_store_middleware()
386
387
  // socket io session middleware
387
388
  io.use((socket, next) => {
388
389
  session_store_middleware(socket.request, {}, next)
@@ -9,9 +9,10 @@ const RedisStore = require("connect-redis").default
9
9
  const is_docker = require("@rpcbase/std/is_docker")
10
10
 
11
11
 
12
- const {SESSION_STORE_PORT, APP_DOMAIN} = process.env
12
+ const {NODE_ENV, 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"
15
16
 
16
17
  const log = debug("rb:session")
17
18
  // log.useColors = true
@@ -28,11 +29,12 @@ const hostname = is_docker() ? "session-store" : "127.0.0.1"
28
29
 
29
30
  console.log("session-store hostname", hostname, "port", SESSION_STORE_PORT)
30
31
 
31
- let session_middleware = null
32
32
 
33
- // EXTREME WARNING: docker issue
34
- // when there is synchronous io redis client fails to connect
35
- setTimeout(async() => {
33
+ const get_session_store_middleware = async() => {
34
+ if (is_production) {
35
+ throw new Error("SESSION STORE MIDDLEWARE CANNOT BE USED IN PRODUCTION")
36
+ }
37
+
36
38
  const reconnectStrategy = (retries) => {
37
39
  log("redis_client::reconnectStrategy::retrying with arg", retries)
38
40
  if (retries < 5) {
@@ -65,7 +67,7 @@ setTimeout(async() => {
65
67
  proxy: true,
66
68
  saveUninitialized: true,
67
69
  // WARNING DO NOT USE IN PROD
68
- secret: "NOT_A_SECRET_BECAUSE_THIS_MIDDLEWARE_IS_NOT_MEANT_TO_BE_USED_IN_PROD",
70
+ secret: "__NOT_A_SECRET_BECAUSE_THIS_MIDDLEWARE_IS_NOT_MEANT_TO_BE_USED_IN_PROD__",
69
71
  resave: true,
70
72
  cookie: {
71
73
  // TODO: set to secure in production
@@ -79,21 +81,16 @@ setTimeout(async() => {
79
81
  // https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain
80
82
  // TODO: WTF IS THIS
81
83
  // if (is_docker() && typeof APP_DOMAIN === "string" && APP_DOMAIN.trim() !== "") {
82
- // log("\n\n")
83
- // log("SETTING COOKIE DOMAIN TO", APP_DOMAIN)
84
- // log("SETTING secure", APP_DOMAIN)
85
- // log("TRUST PROXY TRUE")
86
- // log("\n\n")
87
84
  // session_config.cookie.domain = APP_DOMAIN
88
85
  // // session_config.cookie.secure = true
89
86
  // session_config.cookie.sameSite = false
90
87
  // }
91
88
 
89
+ const session_middleware = session(session_config)
92
90
 
93
- session_middleware = session(session_config)
94
- }, 200)
95
-
96
-
97
- module.exports = (req, res, next) => {
98
- session_middleware(req, res, next)
91
+ return (req, res, next) => {
92
+ session_middleware(req, res, next)
93
+ }
99
94
  }
95
+
96
+ module.exports = get_session_store_middleware
@@ -1,16 +1,18 @@
1
1
  /* @flow */
2
2
  const pc = require("picocolors")
3
3
 
4
+ const get_session_store_middleware = require("./get_session_store_middleware")
5
+
4
6
 
5
7
  const is_development = process.env.NODE_ENV === "development"
6
8
 
7
- module.exports = (app) => {
9
+ module.exports = async(app) => {
8
10
  const has_session_store = process.env.RB_SESSION_STORE === "yes"
9
11
 
10
12
  if (has_session_store) {
11
13
  console.log("using", pc.bold(pc.green("SESSION STORE")))
12
14
 
13
- const session_store_middleware = require("./session_store_middleware")
15
+ const session_store_middleware = await get_session_store_middleware()
14
16
  app.use(session_store_middleware)
15
17
  } else {
16
18
  console.log("using", pc.bold(pc.red("REVERSE-PROXY SESSIONS!")), "if you want to use the session store, start with the --sessions argument")