From 6ebceeb0c5c0dff67faab8b4237b1f33504a7ff9 Mon Sep 17 00:00:00 2001 From: Sivert <316918682+grytchat@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:21:48 +0100 Subject: [PATCH] chore: no rate limits under yarn dev Testing a dev server by hand kept tripping them, with waits of over ten minutes. `yarn dev` now passes --dev, which turns them off. Setting GRYT_DISABLE_RATE_LIMITS=false keeps them on there, and NODE_ENV=production still ignores all of it. Co-Authored-By: Claude Opus 5.5 --- example.env | 2 +- package.json | 2 +- src/utils/rateLimiter.ts | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/example.env b/example.env index 3c0a2b1..529a36a 100644 --- a/example.env +++ b/example.env @@ -104,7 +104,7 @@ DATA_DIR=./data # S3_BUCKET=gryt # Turn uploads off entirely: pictures, files and avatars are refused. # DISABLE_UPLOADS=true -# Turn every rate limit off, for a dev server you're testing on. Ignored when NODE_ENV=production. +# Turn every rate limit off, for a dev server you're testing on. `yarn dev` does this already; set false to keep them on there. Ignored when NODE_ENV=production. # GRYT_DISABLE_RATE_LIMITS=true # Additional channels configuration (JSON array of channel objects) diff --git a/package.json b/package.json index 21d5553..556617c 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "build:selfhosted": "bash build-selfhosted.sh", "build:selfhosted:windows": "bash build-selfhosted.sh windows-x64", "build:selfhosted:linux": "bash build-selfhosted.sh linux-x64", - "dev": "node --watch -r ts-node/register src/index.ts", + "dev": "node --watch -r ts-node/register src/index.ts --dev", "start": "node dist/index.js" } } diff --git a/src/utils/rateLimiter.ts b/src/utils/rateLimiter.ts index a656932..0299395 100644 --- a/src/utils/rateLimiter.ts +++ b/src/utils/rateLimiter.ts @@ -169,10 +169,12 @@ class SlidingWindowLimiter { export const limiter = new SlidingWindowLimiter({ limit: 100, windowMs: 60_000 }); const production = (process.env.NODE_ENV || "").toLowerCase() === "production"; -const limitsOff = process.env.GRYT_DISABLE_RATE_LIMITS === "true"; +const limitsFlag = process.env.GRYT_DISABLE_RATE_LIMITS; +// `yarn dev` passes --dev. Set the flag to false to test limits there. +const limitsOff = limitsFlag === "true" || (limitsFlag !== "false" && process.argv.includes("--dev")); if (limitsOff) { - if (production) consola.warn("GRYT_DISABLE_RATE_LIMITS is ignored with NODE_ENV=production."); - else consola.warn("Rate limits are off (GRYT_DISABLE_RATE_LIMITS=true). Only for a dev server."); + if (production) consola.warn("Rate limits can't be turned off with NODE_ENV=production."); + else consola.warn("Rate limits are off. Only for a dev server."); } export function checkRateLimit(event: string, userId?: string, ip?: string, rule?: RateLimitRule) {