@rpcbase/server 0.469.0 → 0.470.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/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { createInterface } from "node:readline";
11
11
  import { AsyncLocalStorage } from "node:async_hooks";
12
12
  import assert$1 from "assert";
13
13
  import crypto$1, { hkdfSync, scrypt } from "crypto";
14
- import { createProxyMiddleware } from "http-proxy-middleware";
14
+ import httpProxy from "http-proxy-3";
15
15
  import fs from "node:fs/promises";
16
16
  import { Transform } from "node:stream";
17
17
  import { StrictMode, createElement } from "react";
@@ -3261,22 +3261,41 @@ const getDerivedKey = (masterKey, info, length = 32, salt = "") => {
3261
3261
  length
3262
3262
  )).toString("hex");
3263
3263
  };
3264
- const handleProxyError = (err) => {
3265
- console.error(`Proxy error: ${err.message}`);
3264
+ const POSTHOG_INGEST_TARGET = "https://eu.i.posthog.com";
3265
+ const getStatusCode = (errorCode) => {
3266
+ if (typeof errorCode === "string" && /HPE_INVALID/.test(errorCode)) {
3267
+ return 502;
3268
+ }
3269
+ switch (errorCode) {
3270
+ case "ECONNRESET":
3271
+ case "ENOTFOUND":
3272
+ case "ECONNREFUSED":
3273
+ case "ETIMEDOUT":
3274
+ return 504;
3275
+ default:
3276
+ return 500;
3277
+ }
3266
3278
  };
3279
+ const proxy = httpProxy.createProxyServer({
3280
+ changeOrigin: true
3281
+ });
3282
+ proxy.on("error", (err, req, res) => {
3283
+ console.error(`Proxy error: ${err?.message ?? String(err)}`);
3284
+ if (!res || typeof res.writeHead !== "function") return;
3285
+ if (res.headersSent) return;
3286
+ const statusCode = getStatusCode(err?.code);
3287
+ res.writeHead(statusCode);
3288
+ const host = req?.headers?.host ?? "";
3289
+ const url = req?.url ?? "";
3290
+ res.end(`Error occurred while trying to proxy: ${host}${url}`);
3291
+ });
3267
3292
  const metricsIngestProxyMiddleware = (app) => {
3268
- app.use(
3269
- "/ingest",
3270
- createProxyMiddleware({
3271
- target: "https://eu.i.posthog.com",
3272
- changeOrigin: true,
3273
- pathRewrite: { "^/ingest": "" },
3274
- // Remove '/ingest' from the proxied request
3275
- on: {
3276
- error: handleProxyError
3277
- }
3278
- })
3279
- );
3293
+ app.use("/ingest", (req, res) => {
3294
+ if (!req.url) {
3295
+ req.url = "/";
3296
+ }
3297
+ proxy.web(req, res, { target: POSTHOG_INGEST_TARGET });
3298
+ });
3280
3299
  };
3281
3300
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
3282
3301
  let hasWarnedNoReplicationEnabled = false;
@@ -1 +1 @@
1
- {"version":3,"file":"metricsIngestProxyMiddleware.d.ts","sourceRoot":"","sources":["../src/metricsIngestProxyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAA;AAUnC,eAAO,MAAM,4BAA4B,GAAI,KAAK,WAAW,SAY5D,CAAA"}
1
+ {"version":3,"file":"metricsIngestProxyMiddleware.d.ts","sourceRoot":"","sources":["../src/metricsIngestProxyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAA;AAwCxC,eAAO,MAAM,4BAA4B,GAAI,KAAK,WAAW,SAQ5D,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.469.0",
3
+ "version": "0.470.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -75,7 +75,7 @@
75
75
  "connect-redis": "9.0.0",
76
76
  "express-session": "1.18.2",
77
77
  "mongodb": "7.0.0",
78
- "http-proxy-middleware": "3.0.5",
78
+ "http-proxy-3": "1.23.2",
79
79
  "redis": "5.10.0",
80
80
  "ws": "8.18.3"
81
81
  },