@rpcbase/server 0.61.0 → 0.64.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.
@@ -3,9 +3,7 @@ const os = require("os")
3
3
 
4
4
  const get_runtime = () => {
5
5
  if (os.platform() === "darwin") {
6
- console.warn("warning: native mode is tmp disabled")
7
- // return "native"
8
- return "docker"
6
+ return "native"
9
7
  } else {
10
8
  return "docker"
11
9
  }
package/cli/run_docker.js CHANGED
@@ -1,35 +1,61 @@
1
1
  /* @flow */
2
- const {execSync} = require("child_process")
2
+ const {spawn} = require("child_process")
3
3
  const path = require("path")
4
4
 
5
+ const chalk = require("chalk")
6
+
5
7
  const is_production = "yes" === process.env.INFRASTRUCTURE_IS_PRODUCTION
6
8
 
7
- const run_docker = async(infrastructure_dir, proj_prefix) => {
9
+ const run_docker = async(infrastructure_dir, proj_prefix, is_native) => {
8
10
  // env
9
11
  const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
10
12
 
11
13
  // compose files
12
- const compose_files = ["-f common.yml"]
14
+ const compose_files = ["-f", "common.yml"]
15
+ if (!is_native) {
16
+ compose_files.push("-f", "native.yml")
17
+ }
13
18
  if (is_production) {
14
- compose_files.push("-f prod.yml")
19
+ compose_files.push("-f", "prod.yml")
15
20
  }
16
- else compose_files.push("-f dev.yml")
17
-
18
- // console.log("got compose files", compose_files)
21
+ else compose_files.push("-f", "dev.yml")
19
22
 
20
23
  const opts = ["--build", "--remove-orphans"]
21
24
  if (!is_production) opts.push("--abort-on-container-exit")
22
25
 
23
- const cmd = `docker-compose --env-file ${env_path} -p ${proj_prefix} ${compose_files.join(" ")} up ${opts.join(" ")}`
24
-
25
- console.log(cmd)
26
-
27
- try {
28
- execSync(cmd, {stdio: "inherit", cwd: infrastructure_dir})
29
- } catch (err) {
30
- console.log("start_server::error\n", err)
31
- process.exit(1)
32
- }
26
+ const cmd = "docker-compose"
27
+ // const cmd_args = `--env-file ${env_path} -p ${proj_prefix} ${compose_files.join(" ")} up ${opts.join(" ")}`
28
+ const cmd_args = ["--env-file", env_path, "-p", proj_prefix, ...compose_files, "up", ...opts]
29
+
30
+ console.log(cmd_args.join(" "))
31
+
32
+ const ps = spawn(cmd, cmd_args, {cwd: infrastructure_dir})
33
+ ps.stdout.on("data", (data) => {
34
+ const lines = data.toString().split("\n")
35
+ lines.forEach((line) => {
36
+ if (line.trim() === "") {
37
+ return
38
+ }
39
+ process.stdout.write(`${chalk.cyan("docker")}: ${line}\n`)
40
+ })
41
+ })
42
+
43
+ ps.stderr.on("data", (data) => {
44
+ const lines = data.toString().split("\n")
45
+ lines.forEach((line) => {
46
+ if (line.trim() === "") {
47
+ return
48
+ }
49
+ process.stdout.write(`${chalk.cyan("docker")}: ${chalk.yellow(line)}\n`)
50
+ })
51
+ })
52
+
53
+ // try {
54
+ //
55
+ // } catch (err) {
56
+ // console.log("start_server::error\n", err)
57
+ // process.exit(1)
58
+ // }
33
59
  }
34
60
 
35
61
  module.exports = run_docker
package/cli/run_native.js CHANGED
@@ -6,18 +6,19 @@ const fs = require("fs")
6
6
 
7
7
 
8
8
  const run_processes = [
9
- ["mongod", [
10
- "--quiet",
11
- "--port", "$DATABASE_PORT_0",
12
- "--replSet", "rs0",
13
- "--logpath", "/var/log/logs.txt",
14
- ]],
15
- ["mongod", [
16
- "--quiet",
17
- "--port", "$DATABASE_PORT_2",
18
- "--replSet", "rs0",
19
- "--logpath", "/var/log/logs.txt",
20
- ]],
9
+ ["yarn", ["dev"]]
10
+ // ["mongod", [
11
+ // "--quiet",
12
+ // "--port", "$DATABASE_PORT_0",
13
+ // "--replSet", "rs0",
14
+ // "--logpath", "/var/log/logs.txt",
15
+ // ]],
16
+ // ["mongod", [
17
+ // "--quiet",
18
+ // "--port", "$DATABASE_PORT_2",
19
+ // "--replSet", "rs0",
20
+ // "--logpath", "/var/log/logs.txt",
21
+ // ]],
21
22
  ]
22
23
 
23
24
  // const get_env = () => {
@@ -28,16 +29,18 @@ const run_processes = [
28
29
  // }
29
30
 
30
31
 
31
-
32
+ // TODO: run each native process from list
33
+ // TODO: handle process close
32
34
  const run_native = (infrastructure_dir, proj_prefix) => {
33
- console.log("native mode")
35
+ console.log("running in NATIVE mode")
34
36
  // const env = get_env()
35
37
 
36
- const ps = spawn("ls", ["-la"])
38
+ const ps = spawn("yarn", ["dev"], {env: {...process.env, CONTAINER_MODE: "native"}})
37
39
  ps.stdout.on("data", (data) => {
38
- console.log("stdout", data.toString())
40
+ process.stdout.write(data.toString())
39
41
  })
40
42
 
43
+
41
44
  }
42
45
 
43
46
  module.exports = run_native
@@ -20,6 +20,7 @@ const start_server = async() => {
20
20
  const runtime = get_runtime()
21
21
 
22
22
  if (runtime === "native") {
23
+ run_docker(infrastructure_dir, proj_prefix, true)
23
24
  run_native(infrastructure_dir, proj_prefix)
24
25
  } else {
25
26
  run_docker(infrastructure_dir, proj_prefix)
package/database.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const mongoose = require("mongoose")
3
3
  const validator = require("validator")
4
4
 
5
- const {DATABASE_NAME, DATABASE_PORT} = process.env
5
+ const {DATABASE_NAME, DATABASE_PORT, CONTAINER_MODE} = 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,7 +12,9 @@ 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://database:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
15
+ const hostname = CONTAINER_MODE === "native" ? "localhost" : "database"
16
+
17
+ const mongo_url = `mongodb://${hostname}:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
16
18
 
17
19
 
18
20
  module.exports = async() => {
@@ -6,7 +6,7 @@ const is_production = process.env.NODE_ENV === "production"
6
6
  module.exports = (app) => {
7
7
 
8
8
  app.post("/api/__dev_save_coverage", (req, res) => {
9
- console.log(global.__coverage__)
10
- console.log("WOW save coverage")
9
+ console.log("sending coverage for", req.body.path_key)
10
+ res.json(global.__coverage__)
11
11
  })
12
12
  }
package/express/index.js CHANGED
@@ -56,7 +56,7 @@ module.exports = () => {
56
56
 
57
57
  app.get("/api/ping", (req, res) => res.json({message: "pong"}))
58
58
  app.post("/api/ping", (req, res) => res.json({message: "pong"}))
59
- console.log("WITH COVERAGE WOW")
59
+
60
60
  dev_save_coverage(app)
61
61
 
62
62
  return app
@@ -8,12 +8,14 @@ const redis_store = require("connect-redis")(session)
8
8
  // https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
9
9
  // https://github.com/redis/node-redis/issues/1656/
10
10
 
11
- const {SESSION_STORE_PORT} = process.env
11
+ const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
12
12
 
13
13
  if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
14
14
  throw new Error("expected SESSION_STORE_PORT to be a valid port number")
15
15
  }
16
16
 
17
+ const hostname = CONTAINER_MODE === "native" ? "localhost" : "session-store"
18
+
17
19
  let session_middleware = null
18
20
 
19
21
  // extreme warning: docker issue
@@ -36,7 +38,7 @@ setTimeout(async() => {
36
38
 
37
39
  const redis_client = createClient({
38
40
  socket: {
39
- host: "session-store",
41
+ host: hostname,
40
42
  port: SESSION_STORE_PORT,
41
43
  reconnectStrategy,
42
44
  connectTimeout: 10000,
package/index.js CHANGED
@@ -5,6 +5,7 @@ const express = require("./express")
5
5
  const rpc_router = require("./rpc/rpc_router")
6
6
 
7
7
 
8
+
8
9
  module.exports = {
9
10
  client_router,
10
11
  database,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.61.0",
3
+ "version": "0.64.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/rpc/rpc_router.js CHANGED
@@ -17,6 +17,8 @@ const async_wrapper = fn => (req, res, next) => {
17
17
  const rpc_router = (app) => {
18
18
  const rpc_routes = glob.sync(path.join(build_dir, "./rpc/*"))
19
19
 
20
+ // console.log("rpc_routes", rpc_routes)
21
+
20
22
  rpc_routes.forEach((file_path) => {
21
23
  const basename = path.basename(file_path)
22
24
  const route_path = basename.replace(/__slash__/g, "/")