@rpcbase/server 0.220.0 → 0.222.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.
@@ -2,13 +2,17 @@
2
2
  const debug = require("debug")
3
3
  const cors = require("cors")
4
4
 
5
+
6
+ const log = debug("rb:cors")
7
+
8
+
5
9
  const is_production = process.env.IS_PRODUCTION === "yes"
6
10
 
7
11
  const {RB_SKIP_CORS_PATHS, APP_DOMAIN, CLIENT_PORT} = process.env
8
12
 
9
13
  const custom_cors = (app) => {
10
14
 
11
- const skip_paths = (RB_SKIP_CORS_PATHS || "").split(",")
15
+ const skip_paths = (RB_SKIP_CORS_PATHS || "").split(",").filter((p) => !!p)
12
16
 
13
17
  // CORS
14
18
  const cors_origins = is_production ?
@@ -48,8 +52,7 @@ const custom_cors = (app) => {
48
52
  cors_origins.push(`https://${APP_DOMAIN}`)
49
53
  }
50
54
 
51
-
52
- // console.log("setting up cors with origins", JSON.stringify(cors_origins))
55
+ log("cors origins", JSON.stringify(cors_origins, null, 2))
53
56
 
54
57
  const cors_middleware = cors({
55
58
  origin: cors_origins,
@@ -60,6 +63,7 @@ const custom_cors = (app) => {
60
63
  app.use((req, res, next) => {
61
64
  for (const skip_path of skip_paths) {
62
65
  if (req.url.startsWith(skip_path)) {
66
+ log("skip path", req.url)
63
67
  next()
64
68
  return
65
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.220.0",
3
+ "version": "0.222.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -17,8 +17,6 @@ const is_development = process.env.NODE_ENV === "development"
17
17
  // do not serve compression in dev, the assets are only compressed in the github action
18
18
  const COMPRESSED_EXTENSIONS = is_development ? [] : Object.keys(COMPRESSED_EXTENSIONS_MAP)
19
19
 
20
-
21
-
22
20
  const src_path = path.join(process.cwd(), "./src/")
23
21
  const build_dir = path.join(process.cwd(), "build/")
24
22
  const client_build_dir = path.join(build_dir, "./client")
@@ -55,7 +53,7 @@ const serve_file = (req, res, full_path) => {
55
53
  // })
56
54
  // }
57
55
  // gzip
58
- /*else*/ if (accept_encoding.indexOf("gzip") > -1) {
56
+ /*else*/ if (!is_development && accept_encoding.indexOf("gzip") > -1) {
59
57
  res.sendFile(`${file_path}.gz`, {
60
58
  headers: {
61
59
  "Content-Encoding": "gzip",
@@ -1,16 +1,19 @@
1
1
  /* @flow */
2
+ const pc = require("picocolors")
3
+
4
+
2
5
  const is_development = process.env.NODE_ENV === "development"
3
6
 
4
7
  module.exports = (app) => {
5
8
  const has_session_store = process.env.RB_SESSION_STORE === "yes"
6
9
 
7
10
  if (has_session_store) {
8
- console.log("using session store")
11
+ console.log("using", pc.bold(pc.green("SESSION STORE")))
9
12
 
10
13
  const session_store_middleware = require("./session_store_middleware")
11
14
  app.use(session_store_middleware)
12
15
  } else {
13
- console.log("using reverse-proxy sessions")
16
+ console.log("using", pc.bold(pc.red("REVERSE-PROXY SESSIONS")), "if you want to use the session store, start with the --sessions argument")
14
17
 
15
18
  // warn the user
16
19
  if (is_development) {
@@ -1,16 +1,17 @@
1
1
  /* @flow */
2
2
 
3
+ const {SUPPRESS_PROXY_SESSION_WARNING} = process.env
4
+
5
+ const suppress_warning = SUPPRESS_PROXY_SESSION_WARNING === "yes"
3
6
 
4
7
  const warning_proxy_middleware = (req, res, next) => {
5
8
  const {host} = req.headers
6
9
 
7
- if (host.startsWith("localhost:")) {
8
- res.status(500)
9
- res.json({status: "error", message: "are you running with the proxy address ? you shouldn't be using localhost when you are running the app with the reverse proxyy"})
10
- return
11
- } else {
12
- next()
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 proxyy")
13
12
  }
13
+
14
+ next()
14
15
  }
15
16
 
16
17
  module.exports = warning_proxy_middleware