@rpcbase/server 0.51.0 → 0.54.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/cli/run_docker.js CHANGED
@@ -15,6 +15,8 @@ const run_docker = async(infrastructure_dir, proj_prefix) => {
15
15
  }
16
16
  else compose_files.push("-f dev.yml")
17
17
 
18
+ console.log("got compose files", compose_files)
19
+
18
20
  const opts = ["--build", "--remove-orphans"]
19
21
  if (!is_production) opts.push("--abort-on-container-exit")
20
22
 
package/cli/run_native.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* @flow */
2
2
  const {spawn} = require("child_process")
3
- const dotenv = require("dotenv")
3
+ // const dotenv = require("dotenv")
4
4
  const path = require("path")
5
5
  const fs = require("fs")
6
6
 
@@ -20,20 +20,18 @@ const run_processes = [
20
20
  ]],
21
21
  ]
22
22
 
23
-
24
-
25
- const get_env = () => {
26
- const env_path = path.join(process.cwd(), ".env")
27
- const env_buf = fs.readFileSync(env_path)
28
- const env = dotenv.parse(env_buf)
29
- return env
30
- }
23
+ // const get_env = () => {
24
+ // const env_path = path.join(process.cwd(), ".env")
25
+ // const env_buf = fs.readFileSync(env_path)
26
+ // const env = dotenv.parse(env_buf)
27
+ // return env
28
+ // }
31
29
 
32
30
 
33
31
 
34
32
  const run_native = (infrastructure_dir, proj_prefix) => {
35
33
  console.log("native mode")
36
- const env = get_env()
34
+ // const env = get_env()
37
35
 
38
36
  const ps = spawn("ls", ["-la"])
39
37
  ps.stdout.on("data", (data) => {
package/database.js CHANGED
@@ -12,7 +12,8 @@ if (typeof DATABASE_NAME !== "string") {
12
12
  throw new Error("expected DATABASE_NAME to be a string")
13
13
  }
14
14
 
15
- const mongo_url = `mongodb://127.0.0.1:${DATABASE_PORT}/${DATABASE_NAME}`
15
+ const mongo_url = `mongodb://database:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
16
+
16
17
 
17
18
  module.exports = async() => {
18
19
 
package/express/index.js CHANGED
@@ -3,13 +3,13 @@ const cors = require("cors")
3
3
  const express = require("express")
4
4
  const body_parser = require("body-parser")
5
5
 
6
- const get_session_middleware = require("./get_session_middleware")
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
10
10
 
11
11
 
12
- module.exports = async() => {
12
+ module.exports = () => {
13
13
  const app = express()
14
14
  app.use(body_parser.json({limit: "2mb"}))
15
15
 
@@ -50,7 +50,6 @@ module.exports = async() => {
50
50
  credentials: true // enable set-cookie
51
51
  }))
52
52
 
53
- const session_middleware = await get_session_middleware()
54
53
  app.use(session_middleware)
55
54
 
56
55
  app.get("/api/ping", (req, res) => res.json({message: "pong"}))
@@ -0,0 +1,76 @@
1
+ /* @flow */
2
+ const session = require("express-session")
3
+ const validator = require("validator")
4
+ const {createClient} = require("redis")
5
+ const redis_store = require("connect-redis")(session)
6
+
7
+ // WARNING:
8
+ // https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
9
+ // https://github.com/redis/node-redis/issues/1656/
10
+
11
+ const {SESSION_STORE_PORT} = process.env
12
+
13
+ if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
14
+ throw new Error("expected SESSION_STORE_PORT to be a valid port number")
15
+ }
16
+
17
+ let session_middleware = null
18
+
19
+ // extreme warning: when there is blocking io redis client won't connect
20
+ // process.nextTick(async() => {
21
+ setTimeout(async() => {
22
+ if (!SESSION_STORE_PORT) {
23
+ return
24
+ }
25
+
26
+ const reconnectStrategy = (retries) => {
27
+ console.log("redis_client::reconnectStrategy::retrying with arg", retries)
28
+ if (retries < 5) {
29
+ console.log("retry count:", retries, "retrying in 1s")
30
+ return 4000
31
+ } else {
32
+ return new Error("max retries expiered")
33
+ }
34
+ }
35
+
36
+ const redis_client = createClient({
37
+ socket: {
38
+ host: "session-store",
39
+ port: SESSION_STORE_PORT,
40
+ reconnectStrategy,
41
+ connectTimeout: 10000,
42
+ keepAlive: 0,
43
+ },
44
+ legacyMode: true,
45
+ })
46
+
47
+
48
+ redis_client.on("ready", () => {
49
+ console.log("session-storage::redis_client connected")
50
+ })
51
+
52
+ const res = await redis_client.connect()
53
+
54
+ session_middleware = session({
55
+ store: new redis_store({client: redis_client}),
56
+ proxy: true,
57
+ saveUninitialized: false,
58
+ // TODO: use session secret from env
59
+ secret: "session secret wowow",
60
+ resave: false,
61
+ })
62
+
63
+ }, 500)
64
+
65
+
66
+ module.exports = (req, res, next) => {
67
+ if (!SESSION_STORE_PORT) {
68
+ return next()
69
+ }
70
+
71
+ if (session_middleware) {
72
+ session_middleware(req, res, next)
73
+ } else {
74
+ console.warn("session middleware not set yet")
75
+ }
76
+ }
@@ -0,0 +1,19 @@
1
+ # docker-compose
2
+ version: "3"
3
+
4
+ services:
5
+ # connect-redis session store
6
+ session-store:
7
+ image: redis:6.2.7-alpine
8
+ volumes:
9
+ - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
10
+ - ./data/session-store/log/:/var/log/
11
+ networks:
12
+ - local-network
13
+ ports:
14
+ - "127.0.0.1:$SESSION_STORE_PORT:$SESSION_STORE_PORT"
15
+ command: [
16
+ "redis-server",
17
+ "/usr/local/etc/redis/redis.conf",
18
+ "--port", $SESSION_STORE_PORT
19
+ ]