@rpcbase/server 0.44.0 → 0.47.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
@@ -13,8 +13,7 @@ let is_command = false
13
13
  const args = yargs(hideBin(process.argv))
14
14
  .command("start", "run server/infrastructure", () => {}, (argv) => {
15
15
  is_command = true
16
- console.log("run start server/infrastructure")
17
- start_server(argv)
16
+ start_server()
18
17
  })
19
18
  .command("ping", "ping", () => {}, (argv) => {
20
19
  is_command = true
package/cli/run_docker.js CHANGED
@@ -4,12 +4,10 @@ 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, args) => {
7
+ const run_docker = async(infrastructure_dir, proj_prefix) => {
8
8
  // env
9
9
  const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
10
10
 
11
- console.log("ICI ARGS", args)
12
-
13
11
  // compose files
14
12
  const compose_files = ["-f common.yml"]
15
13
  if (is_production) compose_files.push("-f prod.yml")
@@ -17,11 +15,11 @@ const run_docker = async(infrastructure_dir, proj_prefix, args) => {
17
15
 
18
16
  const opts = ["--build", "--remove-orphans"]
19
17
  if (!is_production) opts.push("--abort-on-container-exit")
20
- if (args.detach) opts.push("--detach")
21
18
 
22
19
  const cmd = `docker-compose --env-file ${env_path} -p ${proj_prefix} ${compose_files.join(" ")} up ${opts.join(" ")}`
23
20
 
24
21
  console.log(cmd)
22
+
25
23
  try {
26
24
  execSync(cmd, {stdio: "inherit", cwd: infrastructure_dir})
27
25
  } catch (err) {
@@ -10,7 +10,7 @@ const run_native = require("./run_native")
10
10
  // TODO: auto create network if necessary
11
11
  // docker network create local-network
12
12
 
13
- const start_server = async(args) => {
13
+ const start_server = async() => {
14
14
 
15
15
  const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
16
16
 
@@ -20,11 +20,10 @@ const start_server = async(args) => {
20
20
 
21
21
  const runtime = get_runtime()
22
22
 
23
- console.log("RUN", runtime)
24
23
  if (runtime === "native") {
25
24
  run_native(infrastructure_dir, proj_prefix)
26
25
  } else {
27
- run_docker(infrastructure_dir, proj_prefix, args)
26
+ run_docker(infrastructure_dir, proj_prefix)
28
27
  }
29
28
 
30
29
  }
package/database.js CHANGED
@@ -15,22 +15,22 @@ if (typeof DATABASE_NAME !== "string") {
15
15
  const replicaset_str = [0, 1, 2].map((i) => `database${i}:${process.env["DATABASE_PORT_" + i]}`)
16
16
  .join(",")
17
17
 
18
- console.log("db connection str:", replicaset_str)
18
+ const mongo_url = `mongodb://${replicaset_str}/${DATABASE_NAME}`
19
+ // &readPreference=secondary
19
20
 
20
- const mongo_url = `mongodb://${replicaset_str}/${DATABASE_NAME}?`
21
- + `replicaSet=rs0`
22
-
23
- // &readPreference=secondary
24
21
 
25
22
  module.exports = async() => {
26
- console.log("MONGO_URL", mongo_url)
23
+ console.log("mongo_url", mongo_url)
24
+
27
25
  const ret = await mongoose.connect(mongo_url, {
26
+ replicaSet: "rs0",
28
27
  keepAlive: true,
29
- keepAliveInitialDelay: 10000,
28
+ keepAliveInitialDelay: 5000,
30
29
  minPoolSize: 3,
30
+ serverSelectionTimeoutMS: 5000,
31
+ family: 4, // force ipv4
31
32
  })
32
33
 
33
- // mongoose.connection.on("")
34
34
  mongoose.connection.on("disconnected", (arg) => {
35
35
  console.log("Mongoose disconnected", arg)
36
36
  })
@@ -39,7 +39,6 @@ module.exports = async() => {
39
39
  console.log("Mongoose connection error", arg)
40
40
  })
41
41
 
42
- // console.log("Mongoose connect got ret", ret)
43
- // console.log("waiting after return", ret)
44
- // TODO: handle connection retry and pools
42
+
43
+
45
44
  }
package/express/index.js CHANGED
@@ -38,11 +38,11 @@ module.exports = () => {
38
38
  // local dev origins
39
39
  [
40
40
  `http://localhost:${CLIENT_PORT}`,
41
+ // WARNING: hardcoded port
41
42
  "http://localhost:8090", // TMP: used by client of admin
42
43
  "localhost",
43
44
  ]
44
45
 
45
- // console.log("SETUP CORS", cors_origins)
46
46
 
47
47
  app.use(cors({
48
48
  origin: cors_origins,
package/mailer/index.js CHANGED
@@ -1,8 +1,21 @@
1
1
  /* @flow */
2
2
  const postmark = require("postmark")
3
3
 
4
- const {POSTMARK_API_KEY} = process.env
4
+ const {POSTMARK_API_KEY, IS_PRODUCTION} = process.env
5
5
 
6
- const client = new postmark.ServerClient(POSTMARK_API_KEY)
6
+ const is_production = IS_PRODUCTION === "yes"
7
+
8
+ let client
9
+
10
+ if (is_production) {
11
+ client = new postmark.ServerClient(POSTMARK_API_KEY)
12
+ } else {
13
+ client = {
14
+ sendEmail: async(payload) => {
15
+ console.log("sendEmail disabled outside of production")
16
+ console.log("From:", payload.From, "To:", payload.To, "Subject:", payload.Subject)
17
+ }
18
+ }
19
+ }
7
20
 
8
21
  module.exports = client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.44.0",
3
+ "version": "0.47.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/rpc/rpc_router.js CHANGED
@@ -17,9 +17,6 @@ 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
-
21
- console.log("rpc router setup")
22
-
23
20
  rpc_routes.forEach((file_path) => {
24
21
  const basename = path.basename(file_path)
25
22
  const route_path = basename.replace(/__slash__/g, "/")