@rpcbase/server 0.54.0 → 0.57.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.
@@ -0,0 +1 @@
1
+ admin middleware that exposes models, schemas etc
package/admin/index.js ADDED
@@ -0,0 +1,43 @@
1
+ // /* @flow */
2
+ // const fs = require("fs")
3
+ // const path = require("path")
4
+ // const glob = require("glob")
5
+ // const debug = require("debug")
6
+ //
7
+ // const src_path = path.join(process.cwd(), "./src/")
8
+ // const build_dir = path.join(process.cwd(), "build/")
9
+ //
10
+ //
11
+ // const async_wrapper = fn => (req, res, next) => {
12
+ // Promise.resolve(fn(req, res, next))
13
+ // .catch(next)
14
+ // }
15
+ //
16
+ //
17
+ // const rpc_router = (app) => {
18
+ // const rpc_routes = glob.sync(path.join(build_dir, "./rpc/*"))
19
+ //
20
+ // rpc_routes.forEach((file_path) => {
21
+ // const basename = path.basename(file_path)
22
+ // const route_path = basename.replace(/__slash__/g, "/")
23
+ // const module_path = path.join(src_path, `${route_path}.js`)
24
+ //
25
+ // // if module not found, remove created route file
26
+ // if (!fs.existsSync(module_path)) {
27
+ // fs.unlinkSync(file_path)
28
+ // console.log("removed inexistant rpc route", basename, "with module path", module_path)
29
+ // }
30
+ //
31
+ // const rpc_fn = require(module_path)
32
+ // app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
33
+ //
34
+ // console.log(`POST /rpc/${route_path}`)
35
+ // // TODO: add jaegerclient / opentelemetry
36
+ // const result = await rpc_fn(req.body, {req})
37
+ // res.json(result)
38
+ // }))
39
+ // })
40
+ //
41
+ // }
42
+ //
43
+ // module.exports = rpc_router
package/bin.js CHANGED
@@ -8,6 +8,7 @@ const {hideBin} = require("yargs/helpers")
8
8
 
9
9
  const start_server = require("./cli/start_server")
10
10
  const build_server = require("./cli/build_server")
11
+ const run_agent = require("./cli/run_agent")
11
12
 
12
13
  let is_command = false
13
14
 
@@ -16,6 +17,10 @@ const args = yargs(hideBin(process.argv))
16
17
  is_command = true
17
18
  start_server()
18
19
  })
20
+ .command("agent", "run the agent", () => {}, (argv) => {
21
+ is_command = true
22
+ run_agent()
23
+ })
19
24
  .command("build", "build server", () => {}, (argv) => {
20
25
  is_command = true
21
26
  build_server()
@@ -33,5 +38,5 @@ const args = yargs(hideBin(process.argv))
33
38
  .parse()
34
39
 
35
40
  if (!is_command) {
36
- console.log("default command")
41
+ console.log("default com22mand")
37
42
  }
@@ -0,0 +1,33 @@
1
+ /* @flow */
2
+ const path = require("path")
3
+ const fs = require("fs")
4
+
5
+ // const get_runtime = require("./get_runtime")
6
+ // const run_docker = require("./run_docker")
7
+ // const run_native = require("./run_native")
8
+ const {run} = require("@rpcbase/agent")
9
+
10
+ const run_agent = async() => {
11
+ const cwd = process.cwd()
12
+ const proj_parent_dir = path.join(cwd, "../../")
13
+ const proj_prefix = path.basename(proj_parent_dir)
14
+
15
+ console.log("RUN AGENT", proj_prefix)
16
+ run(proj_prefix)
17
+ // const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
18
+ //
19
+ // // prefix
20
+ // const proj_parent_dir = path.join(infrastructure_dir, "../../")
21
+ // const proj_prefix = path.basename(proj_parent_dir)
22
+ //
23
+ // const runtime = get_runtime()
24
+ //
25
+ // if (runtime === "native") {
26
+ // run_native(infrastructure_dir, proj_prefix)
27
+ // } else {
28
+ // run_docker(infrastructure_dir, proj_prefix)
29
+ // }
30
+
31
+ }
32
+
33
+ module.exports = run_agent
package/cli/run_docker.js CHANGED
@@ -15,7 +15,7 @@ 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)
18
+ // console.log("got compose files", compose_files)
19
19
 
20
20
  const opts = ["--build", "--remove-orphans"]
21
21
  if (!is_production) opts.push("--abort-on-container-exit")
@@ -0,0 +1,45 @@
1
+ /* @flow */
2
+ const crypto = require("crypto")
3
+
4
+ const ALGORITHM = "aes-256-cbc"
5
+ const {CRYPTO_SECRET} = process.env
6
+
7
+ if (!CRYPTO_SECRET || CRYPTO_SECRET === "") {
8
+ throw new Error("CRYPTO_SECRET not found in env")
9
+ }
10
+
11
+ const key = crypto.createHash("sha256")
12
+ .update(String(CRYPTO_SECRET))
13
+ .digest()
14
+
15
+
16
+ const encrypt = (text) => {
17
+ const iv = crypto.randomBytes(16)
18
+ const cipher = crypto.createCipheriv(ALGORITHM, key, iv)
19
+
20
+ const encrypted = Buffer.concat([
21
+ cipher.update(text),
22
+ cipher.final()
23
+ ])
24
+
25
+ return {
26
+ iv: iv.toString("hex"),
27
+ content: encrypted.toString("hex")
28
+ }
29
+ }
30
+
31
+ const decrypt = (hash) => {
32
+ const decipher = crypto.createDecipheriv(
33
+ ALGORITHM, key, Buffer.from(hash.iv, "hex")
34
+ )
35
+
36
+ const decrpyted = Buffer.concat([
37
+ decipher.update(Buffer.from(hash.content, "hex")),
38
+ decipher.final(),
39
+ ])
40
+
41
+ return decrpyted.toString()
42
+ }
43
+
44
+
45
+ module.exports = {encrypt, decrypt}
package/database.js CHANGED
@@ -16,7 +16,6 @@ const mongo_url = `mongodb://database:${DATABASE_PORT}/${DATABASE_NAME}?directCo
16
16
 
17
17
 
18
18
  module.exports = async() => {
19
-
20
19
  // set listeners before attempting to connect
21
20
  mongoose.connection.on("connected", () => {
22
21
  console.log("mongoose connected")
@@ -32,13 +31,13 @@ module.exports = async() => {
32
31
  console.log("mongoose connection error", err)
33
32
  })
34
33
 
35
-
36
34
  console.log("connect mongo_url", mongo_url)
37
35
 
38
36
  const connect_opts = {
39
37
  keepAlive: true,
40
38
  keepAliveInitialDelay: 5000,
41
39
  minPoolSize: 5,
40
+ maxPoolSize: 1024 * 1024,
42
41
  family: 4, // force ipv4
43
42
  }
44
43
 
@@ -16,7 +16,8 @@ if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PO
16
16
 
17
17
  let session_middleware = null
18
18
 
19
- // extreme warning: when there is blocking io redis client won't connect
19
+ // extreme warning: docker issue
20
+ // when there is synchronous io redis client fails to connect
20
21
  // process.nextTick(async() => {
21
22
  setTimeout(async() => {
22
23
  if (!SESSION_STORE_PORT) {
@@ -60,7 +61,7 @@ setTimeout(async() => {
60
61
  resave: false,
61
62
  })
62
63
 
63
- }, 500)
64
+ }, 300)
64
65
 
65
66
 
66
67
  module.exports = (req, res, next) => {
@@ -257,7 +257,7 @@ loglevel notice
257
257
  # Specify the log file name. Also the empty string can be used to force
258
258
  # Redis to log on the standard output. Note that if you use standard
259
259
  # output for logging but daemonize, logs will be sent to /dev/null
260
- logfile ""
260
+ logfile "/var/log/redis/logs.txt"
261
261
 
262
262
  # To enable logging to the system logger, just set 'syslog-enabled' to yes,
263
263
  # and optionally update the other syslog parameters to suit your needs.
package/mailer/index.js CHANGED
@@ -12,7 +12,7 @@ if (is_production) {
12
12
  } else {
13
13
  client = {
14
14
  sendEmail: async(payload) => {
15
- console.log("sendEmail disabled outside of production")
15
+ console.log("sendEmail disabled when not in production")
16
16
  console.log("From:", payload.From, "To:", payload.To, "Subject:", payload.Subject)
17
17
  }
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.54.0",
3
+ "version": "0.57.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
+ "@rpcbase/agent": "0.3.0",
13
14
  "body-parser": "1.20.0",
14
15
  "connect-redis": "6.1.3",
15
16
  "cors": "2.8.5",
package/rpc/rpc_router.js CHANGED
@@ -30,11 +30,10 @@ const rpc_router = (app) => {
30
30
 
31
31
  const rpc_fn = require(module_path)
32
32
  app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
33
- // console.log("GOT REQ", req.body)
33
+
34
34
  console.log(`POST /rpc/${route_path}`)
35
35
  // TODO: add jaegerclient / opentelemetry
36
36
  const result = await rpc_fn(req.body, {req})
37
-
38
37
  res.json(result)
39
38
  }))
40
39
  })