@rpcbase/server 0.61.0 → 0.62.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/get_runtime.js +2 -3
- package/cli/run_docker.js +17 -10
- package/cli/run_native.js +19 -16
- package/cli/start_server.js +1 -0
- package/database.js +4 -2
- package/express/dev_save_coverage.js +2 -2
- package/express/session_middleware.js +4 -2
- package/package.json +1 -1
- package/rpc/rpc_router.js +2 -0
package/cli/get_runtime.js
CHANGED
|
@@ -3,9 +3,8 @@ const os = require("os")
|
|
|
3
3
|
|
|
4
4
|
const get_runtime = () => {
|
|
5
5
|
if (os.platform() === "darwin") {
|
|
6
|
-
console.warn("
|
|
7
|
-
|
|
8
|
-
return "docker"
|
|
6
|
+
console.warn("warning22222: native mode is tmp disabled")
|
|
7
|
+
return "native"
|
|
9
8
|
} else {
|
|
10
9
|
return "docker"
|
|
11
10
|
}
|
package/cli/run_docker.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const {
|
|
2
|
+
const {exec} = require("child_process")
|
|
3
3
|
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) => {
|
|
7
|
+
const run_docker = async(infrastructure_dir, proj_prefix, is_native) => {
|
|
8
8
|
// env
|
|
9
9
|
const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
|
|
10
10
|
|
|
11
11
|
// compose files
|
|
12
12
|
const compose_files = ["-f common.yml"]
|
|
13
|
+
if (!is_native) {
|
|
14
|
+
compose_files.push("-f native.yml")
|
|
15
|
+
}
|
|
13
16
|
if (is_production) {
|
|
14
17
|
compose_files.push("-f prod.yml")
|
|
15
18
|
}
|
|
16
19
|
else compose_files.push("-f dev.yml")
|
|
17
20
|
|
|
18
|
-
// console.log("got compose files", compose_files)
|
|
19
|
-
|
|
20
21
|
const opts = ["--build", "--remove-orphans"]
|
|
21
22
|
if (!is_production) opts.push("--abort-on-container-exit")
|
|
22
23
|
|
|
@@ -24,12 +25,18 @@ const run_docker = async(infrastructure_dir, proj_prefix) => {
|
|
|
24
25
|
|
|
25
26
|
console.log(cmd)
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
28
|
+
exec(cmd, {stdio: "inherit", cwd: infrastructure_dir}, (err) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
console.log("GOT ERRR", err)
|
|
31
|
+
}
|
|
32
|
+
console.log("docker process exited")
|
|
33
|
+
})
|
|
34
|
+
// try {
|
|
35
|
+
//
|
|
36
|
+
// } catch (err) {
|
|
37
|
+
// console.log("start_server::error\n", err)
|
|
38
|
+
// process.exit(1)
|
|
39
|
+
// }
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
module.exports = run_docker
|
package/cli/run_native.js
CHANGED
|
@@ -6,18 +6,19 @@ const fs = require("fs")
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const run_processes = [
|
|
9
|
-
["
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
["yarn", ["dev"]]
|
|
10
|
+
// ["mongod", [
|
|
11
|
+
// "--quiet",
|
|
12
|
+
// "--port", "$DATABASE_PORT_0",
|
|
13
|
+
// "--replSet", "rs0",
|
|
14
|
+
// "--logpath", "/var/log/logs.txt",
|
|
15
|
+
// ]],
|
|
16
|
+
// ["mongod", [
|
|
17
|
+
// "--quiet",
|
|
18
|
+
// "--port", "$DATABASE_PORT_2",
|
|
19
|
+
// "--replSet", "rs0",
|
|
20
|
+
// "--logpath", "/var/log/logs.txt",
|
|
21
|
+
// ]],
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
// const get_env = () => {
|
|
@@ -28,16 +29,18 @@ const run_processes = [
|
|
|
28
29
|
// }
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
// TODO: run each native process from list
|
|
33
|
+
// TODO: handle process close
|
|
32
34
|
const run_native = (infrastructure_dir, proj_prefix) => {
|
|
33
|
-
console.log("
|
|
35
|
+
console.log("running in NATIVE mode")
|
|
34
36
|
// const env = get_env()
|
|
35
37
|
|
|
36
|
-
const ps = spawn("
|
|
38
|
+
const ps = spawn("yarn", ["dev"], {env: {...process.env, CONTAINER_MODE: "native"}})
|
|
37
39
|
ps.stdout.on("data", (data) => {
|
|
38
|
-
|
|
40
|
+
process.stdout.write(data.toString())
|
|
39
41
|
})
|
|
40
42
|
|
|
43
|
+
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
module.exports = run_native
|
package/cli/start_server.js
CHANGED
package/database.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const mongoose = require("mongoose")
|
|
3
3
|
const validator = require("validator")
|
|
4
4
|
|
|
5
|
-
const {DATABASE_NAME, DATABASE_PORT} = process.env
|
|
5
|
+
const {DATABASE_NAME, DATABASE_PORT, CONTAINER_MODE} = process.env
|
|
6
6
|
|
|
7
7
|
if (typeof DATABASE_PORT !== "string" || !validator.isPort(DATABASE_PORT)) {
|
|
8
8
|
throw new Error("expected DATABASE_PORT to be a valid port number")
|
|
@@ -12,7 +12,9 @@ if (typeof DATABASE_NAME !== "string") {
|
|
|
12
12
|
throw new Error("expected DATABASE_NAME to be a string")
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const hostname = CONTAINER_MODE === "native" ? "localhost" : "database"
|
|
16
|
+
|
|
17
|
+
const mongo_url = `mongodb://${hostname}:${DATABASE_PORT}/${DATABASE_NAME}?directConnection=true&replicaSet=rs0`
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
module.exports = async() => {
|
|
@@ -6,7 +6,7 @@ const is_production = process.env.NODE_ENV === "production"
|
|
|
6
6
|
module.exports = (app) => {
|
|
7
7
|
|
|
8
8
|
app.post("/api/__dev_save_coverage", (req, res) => {
|
|
9
|
-
console.log(
|
|
10
|
-
|
|
9
|
+
console.log("sending coverage for", req.body.path_key)
|
|
10
|
+
res.json(global.__coverage__)
|
|
11
11
|
})
|
|
12
12
|
}
|
|
@@ -8,12 +8,14 @@ const redis_store = require("connect-redis")(session)
|
|
|
8
8
|
// https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
|
|
9
9
|
// https://github.com/redis/node-redis/issues/1656/
|
|
10
10
|
|
|
11
|
-
const {SESSION_STORE_PORT} = process.env
|
|
11
|
+
const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
|
|
12
12
|
|
|
13
13
|
if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
|
|
14
14
|
throw new Error("expected SESSION_STORE_PORT to be a valid port number")
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const hostname = CONTAINER_MODE === "native" ? "localhost" : "session-store"
|
|
18
|
+
|
|
17
19
|
let session_middleware = null
|
|
18
20
|
|
|
19
21
|
// extreme warning: docker issue
|
|
@@ -36,7 +38,7 @@ setTimeout(async() => {
|
|
|
36
38
|
|
|
37
39
|
const redis_client = createClient({
|
|
38
40
|
socket: {
|
|
39
|
-
host:
|
|
41
|
+
host: hostname,
|
|
40
42
|
port: SESSION_STORE_PORT,
|
|
41
43
|
reconnectStrategy,
|
|
42
44
|
connectTimeout: 10000,
|
package/package.json
CHANGED
package/rpc/rpc_router.js
CHANGED
|
@@ -17,6 +17,8 @@ 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
|
+
// console.log("rpc_routes", rpc_routes)
|
|
21
|
+
|
|
20
22
|
rpc_routes.forEach((file_path) => {
|
|
21
23
|
const basename = path.basename(file_path)
|
|
22
24
|
const route_path = basename.replace(/__slash__/g, "/")
|