@rpcbase/server 0.238.0 → 0.240.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/bin.js CHANGED
@@ -8,6 +8,8 @@ const {hideBin} = require("yargs/helpers")
8
8
 
9
9
  const pack = require("./package.json")
10
10
  const start_server_infrastructure = require("./cli/start_server_infrastructure")
11
+ const run_dev_server = require("./cli/run_dev_server")
12
+ const run_dev_worker = require("./cli/run_dev_worker")
11
13
  const build_server = require("./cli/build_server")
12
14
  const check_args = require("./cli/check_args")
13
15
  const run_agent = require("./cli/run_agent")
@@ -35,6 +37,14 @@ const args = yargs(hideBin(process.argv))
35
37
  check_args(args)
36
38
  start_server_infrastructure(args)
37
39
  })
40
+ .command("dev-server", "runs the web server in dev mode", () => {}, (args) => {
41
+ is_command = true
42
+ run_dev_server(args)
43
+ })
44
+ .command("dev-worker", "runs the worker in dev mode", () => {}, (args) => {
45
+ is_command = true
46
+ run_dev_worker(args)
47
+ })
38
48
  .command("agent", "run the agent", () => {}, (args) => {
39
49
  is_command = true
40
50
  run_agent()
@@ -0,0 +1,50 @@
1
+ /* @flow */
2
+ const picocolors = require("picocolors")
3
+ const nodemon = require("nodemon")
4
+
5
+
6
+ const MAX_RECENT_CRASHES = 16
7
+ const CRASH_COOLDOWN_INTERVAL = 10000
8
+ const CRASH_RESTART_DELAY = 1000
9
+
10
+
11
+ const get_dev_watcher = ({script, ...opts}) => {
12
+
13
+ let crash_count = 0
14
+
15
+ const instance = nodemon({
16
+ script,
17
+ ...opts,
18
+ })
19
+
20
+ instance.on("start", () => {
21
+ console.log(picocolors.green(`${script} has started`))
22
+ }).on("quit", () => {
23
+ console.log(picocolors.green(`${script} has quit`))
24
+ process.exit()
25
+ }).on("restart", (files) => {
26
+ console.log(picocolors.green(`${script} restarted due to: ${files?.length} changes`))
27
+ }).on("crash", () => {
28
+ crash_count++
29
+
30
+ if (crash_count > MAX_RECENT_CRASHES) {
31
+ return
32
+ }
33
+
34
+ console.log(picocolors.red(`${script} crashed, will restart`))
35
+
36
+ setTimeout(() => {
37
+ instance.emit("restart")
38
+ }, CRASH_RESTART_DELAY)
39
+ })
40
+
41
+ setInterval(() => {
42
+ if (crash_count > 0) {
43
+ crash_count--
44
+ }
45
+ }, CRASH_COOLDOWN_INTERVAL)
46
+
47
+ return instance
48
+ }
49
+
50
+ module.exports = get_dev_watcher
@@ -0,0 +1,23 @@
1
+ /* @flow */
2
+ const get_dev_watcher = require("./get_dev_watcher")
3
+
4
+ const run_dev_server = (args) => {
5
+
6
+ const watcher = get_dev_watcher({
7
+ script: "server.js",
8
+ ignore: [
9
+ ],
10
+ watch: [
11
+ "./server.js",
12
+ "build/",
13
+ "src/",
14
+ "../../../pms/plugin/",
15
+ "../../../../rpcbase/pkg/access-control/",
16
+ "../../../../rpcbase/pkg/server/"
17
+ ],
18
+ delay: "500ms"
19
+ })
20
+
21
+ }
22
+
23
+ module.exports = run_dev_server
@@ -0,0 +1,22 @@
1
+ /* @flow */
2
+ const get_dev_watcher = require("./get_dev_watcher")
3
+
4
+ const run_dev_worker = (args) => {
5
+
6
+ const watcher = get_dev_watcher({
7
+ script: "worker.js",
8
+ ignore: [
9
+ ],
10
+ watch: [
11
+ "./worker.js",
12
+ "build/",
13
+ "src/",
14
+ "../../../pms/plugin/",
15
+ "../../../../rpcbase/pkg/access-control/",
16
+ "../../../../rpcbase/pkg/server/"
17
+ ],
18
+ delay: "500ms"
19
+ })
20
+ }
21
+
22
+ module.exports = run_dev_worker
package/cli/run_native.js CHANGED
@@ -47,13 +47,11 @@ const get_processes = (args) => {
47
47
  // TODO: add a redis cache
48
48
  const processes = [
49
49
  // web server
50
- // TODO: do not use yarn dev server command
51
- // use command: rb-server dev
52
50
  {
53
51
  name: "server",
54
52
  dirs: [],
55
- // yarn dev
56
- cmd: ["yarn", ["dev"]]
53
+ // yarn dev-server
54
+ cmd: ["yarn", ["dev-server"]]
57
55
  },
58
56
  {
59
57
  name: "worker",
package/mailer/index.js CHANGED
@@ -9,6 +9,9 @@ const {POSTMARK_API_KEY, IS_PRODUCTION, RB_FORCE_SEND_EMAILS} = process.env
9
9
  const is_production = IS_PRODUCTION === "yes"
10
10
  const force_send = RB_FORCE_SEND_EMAILS === "yes"
11
11
 
12
+
13
+ // TMP use proper mock smtp server in development
14
+
12
15
  log("mailer, is_production:", is_production, "env:", JSON.stringify(IS_PRODUCTION))
13
16
 
14
17
  let client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.238.0",
3
+ "version": "0.240.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -28,6 +28,7 @@
28
28
  "lodash": "4.17.21",
29
29
  "mkdirp": "2.1.3",
30
30
  "mongoose": "7.4.3",
31
+ "nodemon": "3.0.1",
31
32
  "picocolors": "1.0.0",
32
33
  "postmark": "3.0.19",
33
34
  "redis": "4.6.7",
@@ -6,14 +6,15 @@ const debug = require("debug")
6
6
 
7
7
  const async_wrapper = require("../helpers/async_wrapper")
8
8
 
9
+
9
10
  const src_path = path.join(process.cwd(), "./src/")
10
11
  const build_dir = path.join(process.cwd(), "build/")
11
12
 
13
+ const log = debug("rb:rpc")
12
14
 
13
- const rpc_router = (app) => {
14
- const rpc_routes = glob.sync(path.join(build_dir, "./rpc/*"))
15
15
 
16
- // console.log("rpc_routes", rpc_routes)
16
+ const rpc_router = (app) => {
17
+ const rpc_routes = glob.sync(path.join(build_dir, "./client/rpc/*"))
17
18
 
18
19
  rpc_routes.forEach((file_path) => {
19
20
  const basename = path.basename(file_path)
@@ -29,7 +30,7 @@ const rpc_router = (app) => {
29
30
  const rpc_fn = require(module_path)
30
31
  app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
31
32
 
32
- console.log(`POST /rpc/${route_path}`)
33
+ log(`POST /rpc/${route_path}`)
33
34
 
34
35
  // TODO: add jaegerclient / opentelemetry
35
36
  const result = await rpc_fn(req.body, {req, res})