@growthbook/proxy
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -12,2 +12,3 @@ "use strict"; | ||
const logger_1 = __importDefault(require("../services/logger")); | ||
const init_1 = require("../init"); | ||
const postConnection = (req, res) => { | ||
@@ -60,3 +61,3 @@ const apiKey = req.body.apiKey; | ||
exports.adminRouter.post("/connection", adminMiddleware_1.adminMiddleware, express_1.default.json({ | ||
limit: (_a = process.env.MAX_PAYLOAD_SIZE) !== null && _a !== void 0 ? _a : "2mb", | ||
limit: (_a = process.env.MAX_PAYLOAD_SIZE) !== null && _a !== void 0 ? _a : init_1.MAX_PAYLOAD_SIZE, | ||
}), postConnection); | ||
@@ -63,0 +64,0 @@ exports.adminRouter.get("/connection/:apiKey", adminMiddleware_1.adminMiddleware, getConnection); |
@@ -28,2 +28,3 @@ "use strict"; | ||
const features_1 = require("../services/features"); | ||
const init_1 = require("../init"); | ||
const getFeatures = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -155,2 +156,3 @@ var _a; | ||
const featuresRouter = (ctx) => { | ||
var _a, _b; | ||
const router = express_1.default.Router(); | ||
@@ -161,6 +163,9 @@ // proxy clients' "get features" endpoint call to GrowthBook, with cache layer | ||
if (ctx.enableRemoteEval) { | ||
router.post("/api/eval/*", apiKeyMiddleware_1.apiKeyMiddleware, express_1.default.json(), sseSupportMiddleware_1.sseSupportMiddleware, getEvaluatedFeatures); | ||
router.post("/api/eval/*", apiKeyMiddleware_1.apiKeyMiddleware, express_1.default.json({ | ||
limit: (_a = process.env.MAX_PAYLOAD_SIZE) !== null && _a !== void 0 ? _a : init_1.MAX_PAYLOAD_SIZE, | ||
}), sseSupportMiddleware_1.sseSupportMiddleware, getEvaluatedFeatures); | ||
} | ||
// subscribe to GrowthBook's "post features" updates, refresh cache, publish to subscribed clients | ||
router.post("/proxy/features", apiKeyMiddleware_1.apiKeyMiddleware, express_1.default.json({ | ||
limit: (_b = process.env.MAX_PAYLOAD_SIZE) !== null && _b !== void 0 ? _b : init_1.MAX_PAYLOAD_SIZE, | ||
verify: (req, res, buf) => (res.locals.rawBody = buf), | ||
@@ -167,0 +172,0 @@ }), webhookVerificationMiddleware_1.default, reencryptionMiddleware_1.reencryptionMiddleware, broadcastEventStreamMiddleware_1.broadcastEventStreamMiddleware, postFeatures); |
import { Context } from "./types"; | ||
export declare const MAX_PAYLOAD_SIZE = "2mb"; | ||
declare const _default: () => Promise<{ | ||
@@ -3,0 +4,0 @@ app: import("express-serve-static-core").Express; |
@@ -38,2 +38,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MAX_PAYLOAD_SIZE = void 0; | ||
const express_1 = __importDefault(require("express")); | ||
@@ -43,2 +44,3 @@ const spdy = __importStar(require("spdy")); | ||
dotenv_1.default.config({ path: "./.env.local" }); | ||
exports.MAX_PAYLOAD_SIZE = "2mb"; | ||
exports.default = () => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -54,3 +56,3 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
verboseDebugging: ["true", "1"].includes((_c = process.env.VERBOSE_DEBUGGING) !== null && _c !== void 0 ? _c : "0"), | ||
maxPayloadSize: (_d = process.env.MAX_PAYLOAD_SIZE) !== null && _d !== void 0 ? _d : "2mb", | ||
maxPayloadSize: (_d = process.env.MAX_PAYLOAD_SIZE) !== null && _d !== void 0 ? _d : exports.MAX_PAYLOAD_SIZE, | ||
// SDK Connections settings: | ||
@@ -75,5 +77,2 @@ createConnectionsFromEnv: ["true", "1"].includes((_e = process.env.CREATE_CONNECTIONS_FROM_ENV) !== null && _e !== void 0 ? _e : "1"), | ||
useCluster: ["true", "1"].includes((_k = process.env.USE_CLUSTER) !== null && _k !== void 0 ? _k : "0"), | ||
clusterRootNodes: process.env.CLUSTER_ROOT_NODES | ||
? process.env.CLUSTER_ROOT_NODES.replace(" ", "").split(",") | ||
: undefined, | ||
clusterRootNodesJSON: process.env.CLUSTER_ROOT_NODES_JSON | ||
@@ -80,0 +79,0 @@ ? JSON.parse(process.env.CLUSTER_ROOT_NODES_JSON) |
@@ -21,3 +21,2 @@ import { ClusterNode, ClusterOptions } from "ioredis"; | ||
useCluster?: boolean; | ||
clusterRootNodes?: string[]; | ||
clusterRootNodesJSON?: ClusterNode[]; | ||
@@ -24,0 +23,0 @@ clusterOptionsJSON?: ClusterOptions; |
@@ -15,3 +15,3 @@ import Redis, { Cluster } from "ioredis"; | ||
private readonly useCluster; | ||
private readonly clusterRootNodes?; | ||
private readonly clusterRootNodesJSON?; | ||
private readonly clusterOptions?; | ||
@@ -21,3 +21,3 @@ private readonly appContext?; | ||
expiresTTL, // 10 minutes | ||
allowStale, connectionUrl, useAdditionalMemoryCache, publishPayloadToChannel, useCluster, clusterRootNodes, clusterRootNodesJSON, clusterOptionsJSON, }?: CacheSettings, appContext?: Context); | ||
allowStale, connectionUrl, useAdditionalMemoryCache, publishPayloadToChannel, useCluster, clusterRootNodesJSON, clusterOptionsJSON, }?: CacheSettings, appContext?: Context); | ||
connect(): Promise<void>; | ||
@@ -29,3 +29,2 @@ get(key: string): Promise<CacheEntry | undefined>; | ||
getsubscriberClient(): Cluster | Redis | undefined; | ||
private transformRootNodes; | ||
} |
@@ -25,3 +25,3 @@ "use strict"; | ||
expiresTTL = 10 * 60, // 10 minutes | ||
allowStale = true, connectionUrl, useAdditionalMemoryCache, publishPayloadToChannel = false, useCluster = false, clusterRootNodes, clusterRootNodesJSON, clusterOptionsJSON, } = {}, appContext) { | ||
allowStale = true, connectionUrl, useAdditionalMemoryCache, publishPayloadToChannel = false, useCluster = false, clusterRootNodesJSON, clusterOptionsJSON, } = {}, appContext) { | ||
this.clientUUID = (0, uuid_1.v4)(); | ||
@@ -34,4 +34,3 @@ this.connectionUrl = connectionUrl; | ||
this.useCluster = useCluster; | ||
this.clusterRootNodes = | ||
clusterRootNodesJSON !== null && clusterRootNodesJSON !== void 0 ? clusterRootNodesJSON : this.transformRootNodes(clusterRootNodes); | ||
this.clusterRootNodesJSON = clusterRootNodesJSON; | ||
this.clusterOptions = clusterOptionsJSON; | ||
@@ -55,4 +54,4 @@ this.appContext = appContext; | ||
else { | ||
if (this.clusterRootNodes) { | ||
this.client = new ioredis_1.default.Cluster(this.clusterRootNodes, this.clusterOptions); | ||
if (this.clusterRootNodesJSON) { | ||
this.client = new ioredis_1.default.Cluster(this.clusterRootNodesJSON, this.clusterOptions); | ||
} | ||
@@ -219,22 +218,4 @@ else { | ||
} | ||
transformRootNodes(rootNodes) { | ||
if (!rootNodes) | ||
return undefined; | ||
return rootNodes | ||
.map((node) => { | ||
try { | ||
const url = new URL(node); | ||
const host = url.protocol + "//" + url.hostname + url.pathname; | ||
const port = parseInt(url.port); | ||
return { host, port }; | ||
} | ||
catch (e) { | ||
logger_1.default.error(e, "Error parsing Redis cluster node"); | ||
return undefined; | ||
} | ||
}) | ||
.filter(Boolean); | ||
} | ||
} | ||
exports.RedisCache = RedisCache; | ||
//# sourceMappingURL=RedisCache.js.map |
@@ -7,3 +7,3 @@ { | ||
"description": "GrowthBook proxy server for caching, realtime updates, telemetry, etc", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "dist/app.js", | ||
@@ -10,0 +10,0 @@ "license": "MIT", |
@@ -5,2 +5,3 @@ import express, { Request, Response } from "express"; | ||
import logger from "../services/logger"; | ||
import { MAX_PAYLOAD_SIZE } from "../init"; | ||
@@ -61,3 +62,3 @@ const postConnection = (req: Request, res: Response) => { | ||
express.json({ | ||
limit: process.env.MAX_PAYLOAD_SIZE ?? "2mb", | ||
limit: process.env.MAX_PAYLOAD_SIZE ?? MAX_PAYLOAD_SIZE, | ||
}), | ||
@@ -64,0 +65,0 @@ postConnection, |
@@ -14,2 +14,3 @@ import express, { NextFunction, Request, Response } from "express"; | ||
import { Context } from "../types"; | ||
import { MAX_PAYLOAD_SIZE } from "../init"; | ||
@@ -185,3 +186,5 @@ const getFeatures = async (req: Request, res: Response, next: NextFunction) => { | ||
apiKeyMiddleware, | ||
express.json(), | ||
express.json({ | ||
limit: process.env.MAX_PAYLOAD_SIZE ?? MAX_PAYLOAD_SIZE, | ||
}), | ||
sseSupportMiddleware, | ||
@@ -197,2 +200,3 @@ getEvaluatedFeatures, | ||
express.json({ | ||
limit: process.env.MAX_PAYLOAD_SIZE ?? MAX_PAYLOAD_SIZE, | ||
verify: (req: Request, res: Response, buf: Buffer) => | ||
@@ -199,0 +203,0 @@ (res.locals.rawBody = buf), |
@@ -7,2 +7,4 @@ import express from "express"; | ||
export const MAX_PAYLOAD_SIZE = "2mb"; | ||
export default async () => { | ||
@@ -19,3 +21,3 @@ const context: Partial<Context> = { | ||
), | ||
maxPayloadSize: process.env.MAX_PAYLOAD_SIZE ?? "2mb", | ||
maxPayloadSize: process.env.MAX_PAYLOAD_SIZE ?? MAX_PAYLOAD_SIZE, | ||
// SDK Connections settings: | ||
@@ -42,5 +44,2 @@ createConnectionsFromEnv: ["true", "1"].includes(process.env.CREATE_CONNECTIONS_FROM_ENV ?? "1"), | ||
useCluster: ["true", "1"].includes(process.env.USE_CLUSTER ?? "0"), | ||
clusterRootNodes: process.env.CLUSTER_ROOT_NODES | ||
? process.env.CLUSTER_ROOT_NODES.replace(" ", "").split(",") | ||
: undefined, | ||
clusterRootNodesJSON: process.env.CLUSTER_ROOT_NODES_JSON | ||
@@ -47,0 +46,0 @@ ? JSON.parse(process.env.CLUSTER_ROOT_NODES_JSON) |
@@ -25,3 +25,2 @@ import { ClusterNode, ClusterOptions } from "ioredis"; | ||
useCluster?: boolean; // for RedisCache | ||
clusterRootNodes?: string[]; // for RedisCache | ||
clusterRootNodesJSON?: ClusterNode[]; // for RedisCache | ||
@@ -28,0 +27,0 @@ clusterOptionsJSON?: ClusterOptions; // for RedisCache |
@@ -25,3 +25,3 @@ import Redis, { Cluster, ClusterNode, ClusterOptions } from "ioredis"; | ||
private readonly useCluster: boolean; | ||
private readonly clusterRootNodes?: ClusterNode[]; | ||
private readonly clusterRootNodesJSON?: ClusterNode[]; | ||
private readonly clusterOptions?: ClusterOptions; | ||
@@ -40,3 +40,2 @@ | ||
useCluster = false, | ||
clusterRootNodes, | ||
clusterRootNodesJSON, | ||
@@ -53,4 +52,3 @@ clusterOptionsJSON, | ||
this.useCluster = useCluster; | ||
this.clusterRootNodes = | ||
clusterRootNodesJSON ?? this.transformRootNodes(clusterRootNodes); | ||
this.clusterRootNodesJSON = clusterRootNodesJSON; | ||
this.clusterOptions = clusterOptionsJSON; | ||
@@ -75,5 +73,5 @@ | ||
} else { | ||
if (this.clusterRootNodes) { | ||
if (this.clusterRootNodesJSON) { | ||
this.client = new Redis.Cluster( | ||
this.clusterRootNodes, | ||
this.clusterRootNodesJSON, | ||
this.clusterOptions, | ||
@@ -275,19 +273,2 @@ ); | ||
} | ||
private transformRootNodes(rootNodes?: string[]): ClusterNode[] | undefined { | ||
if (!rootNodes) return undefined; | ||
return rootNodes | ||
.map((node) => { | ||
try { | ||
const url = new URL(node); | ||
const host = url.protocol + "//" + url.hostname + url.pathname; | ||
const port = parseInt(url.port); | ||
return { host, port }; | ||
} catch (e) { | ||
logger.error(e, "Error parsing Redis cluster node"); | ||
return undefined; | ||
} | ||
}) | ||
.filter(Boolean) as ClusterNode[]; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
235490
4256