@rpcbase/server 0.393.0 → 0.395.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.393.0",
3
+ "version": "0.395.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "scripts": {
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@sentry/node": "9.5.0",
28
- "@sentry/react": "9.5.0",
27
+ "@sentry/node": "9.12.0",
28
+ "@sentry/react": "9.12.0",
29
29
  "@sentry/tracing": "7.120.3",
30
- "connect-redis": "8.0.1",
30
+ "connect-redis": "8.0.2",
31
31
  "express-session": "1.18.1",
32
- "http-proxy-middleware": "3.0.3",
32
+ "http-proxy-middleware": "3.0.5",
33
33
  "redis": "4.7.0",
34
34
  "request-ip": "3.3.0"
35
35
  },
package/src/initServer.ts CHANGED
@@ -4,6 +4,7 @@ import session, { SessionOptions } from "express-session"
4
4
  import {RedisStore} from "connect-redis"
5
5
  import {createClient} from "redis"
6
6
  import requestIp from "request-ip"
7
+ import Sentry from "@sentry/node"
7
8
 
8
9
  // dotenv setup, merge process env with vite process.env file
9
10
  process.env = {
@@ -13,11 +14,23 @@ process.env = {
13
14
  }
14
15
 
15
16
  import { getDerivedKey } from "./getDerivedKey"
16
- import { ingestProxyMiddleware } from "./ingestProxyMiddleware"
17
+ import { metricsIngestProxyMiddleware } from "./metricsIngestProxyMiddleware"
17
18
 
18
19
  const isProduction = process.env.NODE_ENV === "production"
19
20
 
20
21
 
22
+ if (isProduction) {
23
+ const dsn = process.env.SENTRY_DSN || process.env.RB_PUBLIC_SENTRY_DSN
24
+ if (!dsn) {
25
+ console.log("WARNING", "missing SENTRY_DSN")
26
+ } else {
27
+ Sentry.init({
28
+ dsn,
29
+ })
30
+ }
31
+ }
32
+
33
+
21
34
  export const initServer = async (app: Application, serverEnv: { [key: string]: string | undefined }) => {
22
35
  app.disable("x-powered-by")
23
36
 
@@ -25,7 +38,16 @@ export const initServer = async (app: Application, serverEnv: { [key: string]:
25
38
 
26
39
  app.use(requestIp.mw())
27
40
 
28
- ingestProxyMiddleware(app)
41
+ // redirect www to non-www middleware
42
+ app.use((req, res, next) => {
43
+ if (req.headers.host?.startsWith("www.")) {
44
+ const newHost = req.headers.host.replace("www.", "");
45
+ return res.redirect(301, `${req.protocol}://${newHost}${req.originalUrl}`);
46
+ }
47
+ next();
48
+ });
49
+
50
+ metricsIngestProxyMiddleware(app)
29
51
 
30
52
  const sessionSecret = getDerivedKey(serverEnv.MASTER_KEY!, "express_session_key")
31
53
 
@@ -2,7 +2,7 @@ import {Application} from "express"
2
2
  import { createProxyMiddleware } from "http-proxy-middleware"
3
3
 
4
4
 
5
- export const ingestProxyMiddleware = (app: Application) => {
5
+ export const metricsIngestProxyMiddleware = (app: Application) => {
6
6
  app.use(
7
7
  "/ingest",
8
8
  createProxyMiddleware({