@rpcbase/server 0.240.0 → 0.242.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_docker.js +2 -0
- package/package.json +1 -1
- package/src/rpc/rpc_router.js +36 -4
- package/src/sessions/index.js +2 -0
- package/src/sessions/warning_proxy_middleware.js +1 -1
- package/admin/README.md +0 -1
- package/admin/index.js +0 -43
package/cli/run_docker.js
CHANGED
|
@@ -42,6 +42,8 @@ const run_docker = async(infrastructure_dir, proj_prefix, args) => {
|
|
|
42
42
|
ps_env.RB_SESSION_STORE = "yes"
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
console.log("SERVER START WITH SESSIONS DOCKER")
|
|
46
|
+
|
|
45
47
|
// WARNING: blocks the process
|
|
46
48
|
// this is the only way to have docker-compose shut down gracefully
|
|
47
49
|
execSync(`${cmd} ${cmd_args.join(" ")}`, {
|
package/package.json
CHANGED
package/src/rpc/rpc_router.js
CHANGED
|
@@ -7,19 +7,23 @@ const debug = require("debug")
|
|
|
7
7
|
const async_wrapper = require("../helpers/async_wrapper")
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const log = debug("rb:rpc")
|
|
11
|
+
|
|
12
|
+
const server_src_dir = path.join(process.cwd(), "./src/")
|
|
11
13
|
const build_dir = path.join(process.cwd(), "build/")
|
|
14
|
+
const client_dir = path.join(process.cwd(), "../../client/")
|
|
12
15
|
|
|
13
|
-
const
|
|
16
|
+
const is_production = process.env.NODE_ENV === "production"
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
const
|
|
19
|
+
const setup_prod_rpc_routes = (app) => {
|
|
20
|
+
// the difference with the dev router is that routes are loaded at startup time, whereas in dev mode routes are resolved on each request
|
|
17
21
|
const rpc_routes = glob.sync(path.join(build_dir, "./client/rpc/*"))
|
|
18
22
|
|
|
19
23
|
rpc_routes.forEach((file_path) => {
|
|
20
24
|
const basename = path.basename(file_path)
|
|
21
25
|
const route_path = basename.replace(/__slash__/g, "/")
|
|
22
|
-
const module_path = path.join(
|
|
26
|
+
const module_path = path.join(server_src_dir, `${route_path}.js`)
|
|
23
27
|
|
|
24
28
|
// if module not found, remove created route file
|
|
25
29
|
if (!fs.existsSync(module_path)) {
|
|
@@ -37,6 +41,34 @@ const rpc_router = (app) => {
|
|
|
37
41
|
res.json(result)
|
|
38
42
|
}))
|
|
39
43
|
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const setup_dev_rpc_routes = (app) => {
|
|
48
|
+
const rpc_routes = glob.sync(path.join(client_dir, "./build/rpc/*"))
|
|
49
|
+
|
|
50
|
+
app.post("/rpc/*", async_wrapper(async(req, res) => {
|
|
51
|
+
const route_path = req.params[0]
|
|
52
|
+
|
|
53
|
+
const module_path = path.join(server_src_dir, `${route_path}.js`)
|
|
54
|
+
|
|
55
|
+
const rpc_fn = require(module_path)
|
|
56
|
+
log(`POST /rpc/${route_path}`)
|
|
57
|
+
|
|
58
|
+
// TODO: add jaegerclient / opentelemetry
|
|
59
|
+
const result = await rpc_fn(req.body, {req, res})
|
|
60
|
+
res.json(result)
|
|
61
|
+
}))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const rpc_router = (app) => {
|
|
66
|
+
|
|
67
|
+
if (is_production) {
|
|
68
|
+
setup_prod_rpc_routes(app)
|
|
69
|
+
} else {
|
|
70
|
+
setup_dev_rpc_routes(app)
|
|
71
|
+
}
|
|
40
72
|
|
|
41
73
|
}
|
|
42
74
|
|
package/src/sessions/index.js
CHANGED
|
@@ -7,6 +7,8 @@ const is_development = process.env.NODE_ENV === "development"
|
|
|
7
7
|
module.exports = (app) => {
|
|
8
8
|
const has_session_store = process.env.RB_SESSION_STORE === "yes"
|
|
9
9
|
|
|
10
|
+
console.log("WOWOWOW", process.env)
|
|
11
|
+
|
|
10
12
|
if (has_session_store) {
|
|
11
13
|
console.log("using", pc.bold(pc.green("SESSION STORE")))
|
|
12
14
|
|
|
@@ -8,7 +8,7 @@ const warning_proxy_middleware = (req, res, next) => {
|
|
|
8
8
|
const {host} = req.headers
|
|
9
9
|
|
|
10
10
|
if (!suppress_warning && host.startsWith("localhost:")) {
|
|
11
|
-
console.warn("are you running with the proxy address ? you shouldn't be using localhost when you are running the app with the reverse
|
|
11
|
+
console.warn("are you running with the proxy address ? you shouldn't be using localhost when you are running the app with the reverse proxyy22")
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
next()
|
package/admin/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
admin middleware that exposes the local models, schemas etc
|
package/admin/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// /* @flow */
|
|
2
|
-
// const fs = require("fs")
|
|
3
|
-
// const path = require("path")
|
|
4
|
-
// const glob = require("glob")
|
|
5
|
-
// const debug = require("debug")
|
|
6
|
-
//
|
|
7
|
-
// const src_path = path.join(process.cwd(), "./src/")
|
|
8
|
-
// const build_dir = path.join(process.cwd(), "build/")
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// const async_wrapper = fn => (req, res, next) => {
|
|
12
|
-
// Promise.resolve(fn(req, res, next))
|
|
13
|
-
// .catch(next)
|
|
14
|
-
// }
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// const rpc_router = (app) => {
|
|
18
|
-
// const rpc_routes = glob.sync(path.join(build_dir, "./rpc/*"))
|
|
19
|
-
//
|
|
20
|
-
// rpc_routes.forEach((file_path) => {
|
|
21
|
-
// const basename = path.basename(file_path)
|
|
22
|
-
// const route_path = basename.replace(/__slash__/g, "/")
|
|
23
|
-
// const module_path = path.join(src_path, `${route_path}.js`)
|
|
24
|
-
//
|
|
25
|
-
// // if module not found, remove created route file
|
|
26
|
-
// if (!fs.existsSync(module_path)) {
|
|
27
|
-
// fs.unlinkSync(file_path)
|
|
28
|
-
// console.log("removed inexistant rpc route", basename, "with module path", module_path)
|
|
29
|
-
// }
|
|
30
|
-
//
|
|
31
|
-
// const rpc_fn = require(module_path)
|
|
32
|
-
// app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
|
|
33
|
-
//
|
|
34
|
-
// console.log(`POST /rpc/${route_path}`)
|
|
35
|
-
// // TODO: add jaegerclient / opentelemetry
|
|
36
|
-
// const result = await rpc_fn(req.body, {req})
|
|
37
|
-
// res.json(result)
|
|
38
|
-
// }))
|
|
39
|
-
// })
|
|
40
|
-
//
|
|
41
|
-
// }
|
|
42
|
-
//
|
|
43
|
-
// module.exports = rpc_router
|