@rpcbase/server 0.222.0 → 0.224.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/index.js +31 -1
- package/package.json +3 -2
- package/src/client/client_router.js +39 -23
- package/src/models/User.js +7 -8
package/express/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const debug = require("debug")
|
|
|
3
3
|
const express = require("express")
|
|
4
4
|
const body_parser = require("body-parser")
|
|
5
5
|
const request_ip = require("request-ip")
|
|
6
|
+
const Sentry = require("@sentry/node")
|
|
6
7
|
|
|
7
8
|
// functionality middlewares
|
|
8
9
|
const auth = require("../src/auth")
|
|
@@ -14,7 +15,10 @@ const custom_cors = require("./custom_cors")
|
|
|
14
15
|
const log = debug("rb:server")
|
|
15
16
|
|
|
16
17
|
const is_production = process.env.IS_PRODUCTION === "yes"
|
|
17
|
-
const
|
|
18
|
+
const is_development = process.env.NODE_ENV === "development"
|
|
19
|
+
const {APP_DOMAIN, SENTRY_DSN, CLIENT_PORT} = process.env
|
|
20
|
+
|
|
21
|
+
const has_sentry = !!SENTRY_DSN
|
|
18
22
|
|
|
19
23
|
// TODO: document this
|
|
20
24
|
// we could have a larger size, but it's good practice to keep it small to prevent body upload ddos attacks
|
|
@@ -24,8 +28,34 @@ const BODY_MAX_SIZE_MB = 80
|
|
|
24
28
|
log("server is production:", JSON.stringify(is_production))
|
|
25
29
|
|
|
26
30
|
module.exports = () => {
|
|
31
|
+
|
|
27
32
|
const app = express()
|
|
28
33
|
|
|
34
|
+
if (has_sentry && !is_development) {
|
|
35
|
+
Sentry.init({
|
|
36
|
+
dsn: SENTRY_DSN,
|
|
37
|
+
integrations: [
|
|
38
|
+
// enable HTTP calls tracing
|
|
39
|
+
new Sentry.Integrations.Http({
|
|
40
|
+
tracing: true
|
|
41
|
+
}),
|
|
42
|
+
// enable Express.js middleware tracing
|
|
43
|
+
new Sentry.Integrations.Express({
|
|
44
|
+
app
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
47
|
+
// Performance Monitoring
|
|
48
|
+
tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Trace incoming requests
|
|
52
|
+
app.use(Sentry.Handlers.requestHandler());
|
|
53
|
+
app.use(Sentry.Handlers.tracingHandler());
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
29
59
|
app.use(request_ip.mw())
|
|
30
60
|
|
|
31
61
|
app.use(body_parser.json({limit: `${BODY_MAX_SIZE_MB}mb`}))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.224.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@rpcbase/access-control": "0.
|
|
13
|
+
"@rpcbase/access-control": "0.27.0",
|
|
14
14
|
"@rpcbase/agent": "0.30.0",
|
|
15
15
|
"@rpcbase/std": "0.9.0",
|
|
16
|
+
"@sentry/node": "7.64.0",
|
|
16
17
|
"bluebird": "3.7.2",
|
|
17
18
|
"body-parser": "1.20.2",
|
|
18
19
|
"bull": "4.11.2",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const fs = require("fs")
|
|
3
3
|
const path = require("path")
|
|
4
4
|
const glob = require("glob")
|
|
5
|
+
const Sentry = require("@sentry/node")
|
|
5
6
|
|
|
6
7
|
const async_wrapper = require("../helpers/async_wrapper")
|
|
7
8
|
|
|
@@ -13,6 +14,9 @@ const COMPRESSED_EXTENSIONS_MAP = {
|
|
|
13
14
|
".svg": "image/svg+xml",
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
const {SENTRY_DSN, NODE_ENV} = process.env
|
|
18
|
+
const has_sentry = !!SENTRY_DSN
|
|
19
|
+
|
|
16
20
|
const is_development = process.env.NODE_ENV === "development"
|
|
17
21
|
// do not serve compression in dev, the assets are only compressed in the github action
|
|
18
22
|
const COMPRESSED_EXTENSIONS = is_development ? [] : Object.keys(COMPRESSED_EXTENSIONS_MAP)
|
|
@@ -77,33 +81,45 @@ const client_router = (app) => {
|
|
|
77
81
|
const client_routes = get_client_routes()
|
|
78
82
|
|
|
79
83
|
const index_file_path = path.join(client_build_dir, "./index.html")
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
if (fs.existsSync(index_file_path)) {
|
|
85
|
+
const index_file_buffer = fs.readFileSync(index_file_path)
|
|
86
|
+
|
|
87
|
+
app.get("*", async_wrapper(async(req, res, next) => {
|
|
88
|
+
const full_path = req.baseUrl + req.path
|
|
89
|
+
|
|
90
|
+
// TODO: this shouldn't be here,
|
|
91
|
+
// it should be handled by the api and rpc routers being declared before this router
|
|
92
|
+
if (full_path.startsWith("/api/") || full_path.startsWith("/rpc/")) {
|
|
93
|
+
return next()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (client_routes.indexOf(full_path) > -1) {
|
|
97
|
+
serve_file(req, res, full_path)
|
|
98
|
+
return
|
|
99
|
+
} else {
|
|
100
|
+
// TODO: should handle 404 here
|
|
101
|
+
res.writeHead(200, {
|
|
102
|
+
"Content-Type": "text/html"
|
|
103
|
+
})
|
|
104
|
+
res.end(index_file_buffer)
|
|
105
|
+
}
|
|
106
|
+
}))
|
|
83
107
|
}
|
|
108
|
+
// register final error handlers
|
|
84
109
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
if (has_sentry && !is_development) {
|
|
111
|
+
// The error handler must be registered before any other error middleware and after all controllers
|
|
112
|
+
app.use(Sentry.Handlers.errorHandler())
|
|
113
|
+
}
|
|
89
114
|
|
|
90
|
-
// TODO: this shouldn't be here,
|
|
91
|
-
// it should be handled by the api and rpc routers being declared before this router
|
|
92
|
-
if (full_path.startsWith("/api/") || full_path.startsWith("/rpc/")) {
|
|
93
|
-
return next()
|
|
94
|
-
}
|
|
95
115
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
})
|
|
104
|
-
res.end(index_file_buffer)
|
|
105
|
-
}
|
|
106
|
-
}))
|
|
116
|
+
app.use((err, req, res, next) => {
|
|
117
|
+
console.error("server got err", err)
|
|
118
|
+
res.status(500).json({
|
|
119
|
+
status: "error",
|
|
120
|
+
message: "something went wrong",
|
|
121
|
+
})
|
|
122
|
+
})
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
module.exports = client_router
|
package/src/models/User.js
CHANGED
|
@@ -6,6 +6,11 @@ const UserSchema = new mongoose.Schema({
|
|
|
6
6
|
type: String,
|
|
7
7
|
index: true,
|
|
8
8
|
},
|
|
9
|
+
is_email_verified: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: false,
|
|
12
|
+
},
|
|
13
|
+
password_hash: String,
|
|
9
14
|
first_name: {
|
|
10
15
|
type: String,
|
|
11
16
|
default: "",
|
|
@@ -18,17 +23,11 @@ const UserSchema = new mongoose.Schema({
|
|
|
18
23
|
type: String,
|
|
19
24
|
default: "",
|
|
20
25
|
},
|
|
21
|
-
avatar_image: {
|
|
22
|
-
type: String,
|
|
23
|
-
},
|
|
24
26
|
avatar_color: {
|
|
25
27
|
type: String,
|
|
26
28
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
default: false,
|
|
30
|
-
},
|
|
31
|
-
password_hash: String,
|
|
29
|
+
profile_picture: Buffer,
|
|
30
|
+
profile_picture_updated_at_ms: Number,
|
|
32
31
|
devices: {
|
|
33
32
|
type: Array,
|
|
34
33
|
default: [],
|