@rpcbase/server 0.52.0 → 0.55.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 +6 -1
- package/cli/run_agent.js +33 -0
- package/cli/run_docker.js +2 -0
- package/cli/run_native.js +8 -10
- package/database.js +3 -3
- package/express/session_middleware.js +12 -8
- package/infrastructure/compose-redis.yml +19 -0
- package/infrastructure/redis/redis.conf +1877 -0
- package/mailer/index.js +1 -1
- package/package.json +7 -6
package/bin.js
CHANGED
|
@@ -8,6 +8,7 @@ const {hideBin} = require("yargs/helpers")
|
|
|
8
8
|
|
|
9
9
|
const start_server = require("./cli/start_server")
|
|
10
10
|
const build_server = require("./cli/build_server")
|
|
11
|
+
const run_agent = require("./cli/run_agent")
|
|
11
12
|
|
|
12
13
|
let is_command = false
|
|
13
14
|
|
|
@@ -16,6 +17,10 @@ const args = yargs(hideBin(process.argv))
|
|
|
16
17
|
is_command = true
|
|
17
18
|
start_server()
|
|
18
19
|
})
|
|
20
|
+
.command("agent", "run the agent", () => {}, (argv) => {
|
|
21
|
+
is_command = true
|
|
22
|
+
run_agent()
|
|
23
|
+
})
|
|
19
24
|
.command("build", "build server", () => {}, (argv) => {
|
|
20
25
|
is_command = true
|
|
21
26
|
build_server()
|
|
@@ -33,5 +38,5 @@ const args = yargs(hideBin(process.argv))
|
|
|
33
38
|
.parse()
|
|
34
39
|
|
|
35
40
|
if (!is_command) {
|
|
36
|
-
console.log("default
|
|
41
|
+
console.log("default com22mand")
|
|
37
42
|
}
|
package/cli/run_agent.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
|
|
5
|
+
// const get_runtime = require("./get_runtime")
|
|
6
|
+
// const run_docker = require("./run_docker")
|
|
7
|
+
// const run_native = require("./run_native")
|
|
8
|
+
const {run} = require("@rpcbase/agent")
|
|
9
|
+
|
|
10
|
+
const run_agent = async() => {
|
|
11
|
+
const cwd = process.cwd()
|
|
12
|
+
const proj_parent_dir = path.join(cwd, "../../")
|
|
13
|
+
const proj_prefix = path.basename(proj_parent_dir)
|
|
14
|
+
|
|
15
|
+
console.log("RUN AGENT", proj_prefix)
|
|
16
|
+
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
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = run_agent
|
package/cli/run_docker.js
CHANGED
|
@@ -15,6 +15,8 @@ const run_docker = async(infrastructure_dir, proj_prefix) => {
|
|
|
15
15
|
}
|
|
16
16
|
else compose_files.push("-f dev.yml")
|
|
17
17
|
|
|
18
|
+
// console.log("got compose files", compose_files)
|
|
19
|
+
|
|
18
20
|
const opts = ["--build", "--remove-orphans"]
|
|
19
21
|
if (!is_production) opts.push("--abort-on-container-exit")
|
|
20
22
|
|
package/cli/run_native.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const {spawn} = require("child_process")
|
|
3
|
-
const dotenv = require("dotenv")
|
|
3
|
+
// const dotenv = require("dotenv")
|
|
4
4
|
const path = require("path")
|
|
5
5
|
const fs = require("fs")
|
|
6
6
|
|
|
@@ -20,20 +20,18 @@ const run_processes = [
|
|
|
20
20
|
]],
|
|
21
21
|
]
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return env
|
|
30
|
-
}
|
|
23
|
+
// const get_env = () => {
|
|
24
|
+
// const env_path = path.join(process.cwd(), ".env")
|
|
25
|
+
// const env_buf = fs.readFileSync(env_path)
|
|
26
|
+
// const env = dotenv.parse(env_buf)
|
|
27
|
+
// return env
|
|
28
|
+
// }
|
|
31
29
|
|
|
32
30
|
|
|
33
31
|
|
|
34
32
|
const run_native = (infrastructure_dir, proj_prefix) => {
|
|
35
33
|
console.log("native mode")
|
|
36
|
-
const env = get_env()
|
|
34
|
+
// const env = get_env()
|
|
37
35
|
|
|
38
36
|
const ps = spawn("ls", ["-la"])
|
|
39
37
|
ps.stdout.on("data", (data) => {
|
package/database.js
CHANGED
|
@@ -12,10 +12,10 @@ 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://
|
|
15
|
+
const mongo_url = `mongodb://database:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
|
|
16
16
|
|
|
17
|
-
module.exports = async() => {
|
|
18
17
|
|
|
18
|
+
module.exports = async() => {
|
|
19
19
|
// set listeners before attempting to connect
|
|
20
20
|
mongoose.connection.on("connected", () => {
|
|
21
21
|
console.log("mongoose connected")
|
|
@@ -31,13 +31,13 @@ module.exports = async() => {
|
|
|
31
31
|
console.log("mongoose connection error", err)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
|
|
35
34
|
console.log("connect mongo_url", mongo_url)
|
|
36
35
|
|
|
37
36
|
const connect_opts = {
|
|
38
37
|
keepAlive: true,
|
|
39
38
|
keepAliveInitialDelay: 5000,
|
|
40
39
|
minPoolSize: 5,
|
|
40
|
+
maxPoolSize: 1024 * 1024,
|
|
41
41
|
family: 4, // force ipv4
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -16,9 +16,10 @@ if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PO
|
|
|
16
16
|
|
|
17
17
|
let session_middleware = null
|
|
18
18
|
|
|
19
|
-
// extreme warning:
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// extreme warning: docker issue
|
|
20
|
+
// when there is synchronous io redis client fails to connect
|
|
21
|
+
// process.nextTick(async() => {
|
|
22
|
+
setTimeout(async() => {
|
|
22
23
|
if (!SESSION_STORE_PORT) {
|
|
23
24
|
return
|
|
24
25
|
}
|
|
@@ -35,7 +36,7 @@ process.nextTick(async() => {
|
|
|
35
36
|
|
|
36
37
|
const redis_client = createClient({
|
|
37
38
|
socket: {
|
|
38
|
-
host: "
|
|
39
|
+
host: "session-store",
|
|
39
40
|
port: SESSION_STORE_PORT,
|
|
40
41
|
reconnectStrategy,
|
|
41
42
|
connectTimeout: 10000,
|
|
@@ -44,9 +45,12 @@ process.nextTick(async() => {
|
|
|
44
45
|
legacyMode: true,
|
|
45
46
|
})
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
|
|
49
|
+
redis_client.on("ready", () => {
|
|
50
|
+
console.log("session-storage::redis_client connected")
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const res = await redis_client.connect()
|
|
50
54
|
|
|
51
55
|
session_middleware = session({
|
|
52
56
|
store: new redis_store({client: redis_client}),
|
|
@@ -57,7 +61,7 @@ process.nextTick(async() => {
|
|
|
57
61
|
resave: false,
|
|
58
62
|
})
|
|
59
63
|
|
|
60
|
-
})
|
|
64
|
+
}, 300)
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
module.exports = (req, res, next) => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# docker-compose
|
|
2
|
+
version: "3"
|
|
3
|
+
|
|
4
|
+
services:
|
|
5
|
+
# connect-redis session store
|
|
6
|
+
session-store:
|
|
7
|
+
image: redis:6.2.7-alpine
|
|
8
|
+
volumes:
|
|
9
|
+
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
|
|
10
|
+
- ./data/session-store/log/:/var/log/
|
|
11
|
+
networks:
|
|
12
|
+
- local-network
|
|
13
|
+
ports:
|
|
14
|
+
- "127.0.0.1:$SESSION_STORE_PORT:$SESSION_STORE_PORT"
|
|
15
|
+
command: [
|
|
16
|
+
"redis-server",
|
|
17
|
+
"/usr/local/etc/redis/redis.conf",
|
|
18
|
+
"--port", $SESSION_STORE_PORT
|
|
19
|
+
]
|