@rpcbase/server 0.80.0 → 0.83.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/cli/run_native.js CHANGED
@@ -40,7 +40,7 @@ const init_processes = (args) => {
40
40
  const worker_queue_dir = path.join(process.cwd(), "../infrastructure/data/worker-queue/data")
41
41
  const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
42
42
 
43
- console.log("WORKER QUEUE ON PORT", env.WORKER_QUEUE_PORT)
43
+ // console.log("WORKER QUEUE ON PORT", env.WORKER_QUEUE_PORT)
44
44
 
45
45
  // TODO: add a redis cache
46
46
  const processes = [
package/database.js CHANGED
@@ -4,6 +4,9 @@ const isPort = require("validator/lib/isPort")
4
4
 
5
5
  const {DATABASE_NAME, DATABASE_PORT, CONTAINER_MODE} = process.env
6
6
 
7
+
8
+ // database can be set by env variable or passed as paramaters to
9
+
7
10
  if (typeof DATABASE_PORT !== "string" || !isPort(DATABASE_PORT)) {
8
11
  throw new Error("expected DATABASE_PORT to be a valid port number")
9
12
  }
@@ -17,7 +20,8 @@ const hostname = CONTAINER_MODE === "native" ? "localhost" : "database"
17
20
  const mongo_url = `mongodb://${hostname}:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
18
21
 
19
22
 
20
- module.exports = async() => {
23
+ // TODO: handle multiple databases, remove DATABASE_NAME env ??
24
+ module.exports = async(...database_names) => {
21
25
  // set listeners before attempting to connect
22
26
  mongoose.connection.on("connected", () => {
23
27
  console.log("mongoose connected")
@@ -0,0 +1,27 @@
1
+ /* @flow */
2
+
3
+ const DEFAULT_EMPTY_TIMEOUT = 1000 * 60 * 60 // 1h
4
+ const is_production = process.env.NODE_ENV === "production"
5
+
6
+ let _req_count = 0
7
+
8
+
9
+ module.exports = (app) => {
10
+
11
+ if (!is_production) {
12
+ app.use((req, res, next) => {
13
+ _req_count++
14
+ next()
15
+ })
16
+
17
+ setInterval(() => {
18
+ // no requests -> shutdown
19
+ if (_req_count === 0) {
20
+ console.log("dev::incoming requests 0, exiting due to timeout")
21
+ process.exit(0)
22
+ } else {
23
+ _req_count = 0
24
+ }
25
+ }, DEFAULT_EMPTY_TIMEOUT)
26
+ }
27
+ }
package/express/index.js CHANGED
@@ -2,11 +2,13 @@
2
2
  const cors = require("cors")
3
3
  const express = require("express")
4
4
  const body_parser = require("body-parser")
5
+ const request_ip = require("request-ip")
5
6
 
6
7
  // functionality middlewares
7
8
  const auth = require("../src/auth")
8
9
 
9
10
  const dev_save_coverage = require("./dev_save_coverage")
11
+ const dev_stop_timeout = require("./dev_stop_timeout")
10
12
  const session_middleware = require("./session_middleware")
11
13
 
12
14
 
@@ -16,6 +18,9 @@ const {APP_DOMAIN, CLIENT_PORT} = process.env
16
18
 
17
19
  module.exports = () => {
18
20
  const app = express()
21
+
22
+ app.use(request_ip.mw())
23
+
19
24
  app.use(body_parser.json({limit: "2mb"}))
20
25
 
21
26
  app.set("trust proxy", 1)
@@ -63,7 +68,9 @@ module.exports = () => {
63
68
  app.post("/api/ping", (req, res) => res.json({message: "pong"}))
64
69
 
65
70
  auth(app)
71
+
66
72
  dev_save_coverage(app)
73
+ dev_stop_timeout(app)
67
74
 
68
75
  return app
69
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.80.0",
3
+ "version": "0.83.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  "picocolors": "1.0.0",
27
27
  "postmark": "3.0.12",
28
28
  "redis": "4.2.0",
29
+ "request-ip": "3.3.0",
29
30
  "validator": "13.7.0",
30
31
  "yargs": "17.5.1"
31
32
  }