@rpcbase/server 0.59.0 → 0.62.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,8 @@ 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
+ console.warn("warning22222: native mode is tmp disabled")
7
+ return "native"
9
8
  } else {
10
9
  return "docker"
11
10
  }
package/cli/run_agent.js CHANGED
@@ -2,9 +2,6 @@
2
2
  const path = require("path")
3
3
  const fs = require("fs")
4
4
 
5
- // const get_runtime = require("./get_runtime")
6
- // const run_docker = require("./run_docker")
7
- // const run_native = require("./run_native")
8
5
  const {run} = require("@rpcbase/agent")
9
6
 
10
7
  const run_agent = async() => {
@@ -12,22 +9,7 @@ const run_agent = async() => {
12
9
  const proj_parent_dir = path.join(cwd, "../../")
13
10
  const proj_prefix = path.basename(proj_parent_dir)
14
11
 
15
- console.log("RUN AGENT", proj_prefix)
16
12
  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
13
  }
32
14
 
33
15
  module.exports = run_agent
package/cli/run_docker.js CHANGED
@@ -1,22 +1,23 @@
1
1
  /* @flow */
2
- const {execSync} = require("child_process")
2
+ const {exec} = require("child_process")
3
3
  const path = require("path")
4
4
 
5
5
  const is_production = "yes" === process.env.INFRASTRUCTURE_IS_PRODUCTION
6
6
 
7
- const run_docker = async(infrastructure_dir, proj_prefix) => {
7
+ const run_docker = async(infrastructure_dir, proj_prefix, is_native) => {
8
8
  // env
9
9
  const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
10
10
 
11
11
  // compose files
12
12
  const compose_files = ["-f common.yml"]
13
+ if (!is_native) {
14
+ compose_files.push("-f native.yml")
15
+ }
13
16
  if (is_production) {
14
17
  compose_files.push("-f prod.yml")
15
18
  }
16
19
  else compose_files.push("-f dev.yml")
17
20
 
18
- // console.log("got compose files", compose_files)
19
-
20
21
  const opts = ["--build", "--remove-orphans"]
21
22
  if (!is_production) opts.push("--abort-on-container-exit")
22
23
 
@@ -24,12 +25,18 @@ const run_docker = async(infrastructure_dir, proj_prefix) => {
24
25
 
25
26
  console.log(cmd)
26
27
 
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
- }
28
+ exec(cmd, {stdio: "inherit", cwd: infrastructure_dir}, (err) => {
29
+ if (err) {
30
+ console.log("GOT ERRR", err)
31
+ }
32
+ console.log("docker process exited")
33
+ })
34
+ // try {
35
+ //
36
+ // } catch (err) {
37
+ // console.log("start_server::error\n", err)
38
+ // process.exit(1)
39
+ // }
33
40
  }
34
41
 
35
42
  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() => {
@@ -0,0 +1,12 @@
1
+ /* @flow */
2
+
3
+ const is_production = process.env.NODE_ENV === "production"
4
+
5
+
6
+ module.exports = (app) => {
7
+
8
+ app.post("/api/__dev_save_coverage", (req, res) => {
9
+ console.log("sending coverage for", req.body.path_key)
10
+ res.json(global.__coverage__)
11
+ })
12
+ }
package/express/index.js CHANGED
@@ -3,6 +3,7 @@ const cors = require("cors")
3
3
  const express = require("express")
4
4
  const body_parser = require("body-parser")
5
5
 
6
+ const dev_save_coverage = require("./dev_save_coverage")
6
7
  const session_middleware = require("./session_middleware")
7
8
 
8
9
  const is_production = process.env.IS_PRODUCTION === "yes"
@@ -39,7 +40,8 @@ module.exports = () => {
39
40
  [
40
41
  `http://localhost:${CLIENT_PORT}`,
41
42
  // WARNING: hardcoded port
42
- "http://localhost:8090", // TMP: used by client of admin
43
+ "http://localhost:8090", // TMP: used by inspected app from admin
44
+ "http://localhost:9292", // TMP
43
45
  "localhost",
44
46
  ]
45
47
 
@@ -54,6 +56,8 @@ module.exports = () => {
54
56
 
55
57
  app.get("/api/ping", (req, res) => res.json({message: "pong"}))
56
58
  app.post("/api/ping", (req, res) => res.json({message: "pong"}))
59
+ console.log("WITH COVERAGE WOW")
60
+ dev_save_coverage(app)
57
61
 
58
62
  return app
59
63
  }
@@ -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,
@@ -61,6 +63,7 @@ setTimeout(async() => {
61
63
  resave: false,
62
64
  })
63
65
 
66
+ // TODO: is this still necessary
64
67
  }, 300)
65
68
 
66
69
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.59.0",
3
+ "version": "0.62.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
- "@rpcbase/agent": "0.5.0",
13
+ "@rpcbase/agent": "0.6.0",
14
14
  "body-parser": "1.20.0",
15
15
  "connect-redis": "6.1.3",
16
16
  "cors": "2.8.5",
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, "/")