@rpcbase/server 0.81.0 → 0.82.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/express/dev_stop_timeout.js +27 -0
- package/express/index.js +3 -0
- package/package.json +1 -1
|
@@ -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
|
@@ -8,6 +8,7 @@ const request_ip = require("request-ip")
|
|
|
8
8
|
const auth = require("../src/auth")
|
|
9
9
|
|
|
10
10
|
const dev_save_coverage = require("./dev_save_coverage")
|
|
11
|
+
const dev_stop_timeout = require("./dev_stop_timeout")
|
|
11
12
|
const session_middleware = require("./session_middleware")
|
|
12
13
|
|
|
13
14
|
|
|
@@ -67,7 +68,9 @@ module.exports = () => {
|
|
|
67
68
|
app.post("/api/ping", (req, res) => res.json({message: "pong"}))
|
|
68
69
|
|
|
69
70
|
auth(app)
|
|
71
|
+
|
|
70
72
|
dev_save_coverage(app)
|
|
73
|
+
dev_stop_timeout(app)
|
|
71
74
|
|
|
72
75
|
return app
|
|
73
76
|
}
|