@rpcbase/server 0.234.0 → 0.236.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.234.0",
3
+ "version": "0.236.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -48,7 +48,7 @@ const reset_password = async({email}, ctx) => {
48
48
 
49
49
  await reset_token.save()
50
50
 
51
- const reset_url = `https://${APP_DOMAIN}/set-new-password?id=${user._id}&token=${token}`
51
+ const reset_url = `https://${APP_DOMAIN}/set-new-password?uid=${user._id}&token=${token}`
52
52
 
53
53
  const res = await mailer.sendEmail({
54
54
  From: MAILER_FROM_EMAIL,
@@ -1,4 +1,5 @@
1
1
  /* @flow */
2
+ const assert = require("assert")
2
3
  const fs = require("fs")
3
4
  const path = require("path")
4
5
  const glob = require("glob")
@@ -7,19 +8,20 @@ const Sentry = require("@sentry/node")
7
8
  const async_wrapper = require("../helpers/async_wrapper")
8
9
 
9
10
 
10
- const COMPRESSED_EXTENSIONS_MAP = {
11
+ const MIME_TYPES = {
11
12
  ".css": "text/css",
12
13
  ".js": "text/javascript",
13
14
  ".json": "application/json",
14
15
  ".svg": "image/svg+xml",
16
+ ".woff2": "font/woff2",
17
+ ".png": "image/png",
15
18
  }
16
19
 
17
20
  const {SENTRY_DSN, NODE_ENV} = process.env
18
21
  const has_sentry = !!SENTRY_DSN
19
22
 
20
23
  const is_development = NODE_ENV === "development"
21
- // do not serve compression in dev, the assets are only compressed in the github action
22
- const COMPRESSED_EXTENSIONS = is_development ? [] : Object.keys(COMPRESSED_EXTENSIONS_MAP)
24
+
23
25
 
24
26
  const src_path = path.join(process.cwd(), "./src/")
25
27
  const build_dir = path.join(process.cwd(), "build/")
@@ -41,38 +43,17 @@ const get_client_routes = () => {
41
43
  const serve_file = (req, res, full_path) => {
42
44
  const file_path = path.join(client_build_dir, full_path)
43
45
 
44
- const extname = path.extname(full_path)
45
- const has_compression = COMPRESSED_EXTENSIONS.includes(extname)
46
-
47
- if (has_compression) {
48
- const accept_encoding = req.headers["accept-encoding"]
49
- // brotli
50
- if (accept_encoding.indexOf("br") > -1) {
51
- res.sendFile(`${file_path}.br`, {
52
- headers: {
53
- "Content-Encoding": "br",
54
- "Content-Type": COMPRESSED_EXTENSIONS_MAP[extname],
55
- }
56
- })
57
- }
58
- // gzip
59
- else if (!is_development && accept_encoding.indexOf("gzip") > -1) {
60
- res.sendFile(`${file_path}.gz`, {
61
- headers: {
62
- "Content-Encoding": "gzip",
63
- "Content-Type": COMPRESSED_EXTENSIONS_MAP[extname],
64
- }
65
- })
66
- }
67
- // unknown accept-encoding
68
- else {
69
- res.sendFile(file_path)
46
+ const extname = path.extname(file_path)
47
+
48
+ const content_type = MIME_TYPES[extname]
49
+ assert(content_type, "unable to resolve content type")
50
+
51
+ res.sendFile(file_path, {
52
+ headers: {
53
+ "Cache-Control": `public, max-age=1800`, // 30 mins
54
+ "Content-Type": content_type,
70
55
  }
71
- }
72
- // not compressed
73
- else {
74
- res.sendFile(file_path)
75
- }
56
+ })
76
57
  }
77
58
 
78
59
 
@@ -112,6 +93,7 @@ const client_router = (app) => {
112
93
  }
113
94
 
114
95
 
96
+ // TODO: this should not be here
115
97
  app.use((err, req, res, next) => {
116
98
  console.error("server got err", err)
117
99
  res.status(500).json({