Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
8 changes: 5 additions & 3 deletions src/utils/rateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading