diff --git a/config/example.env b/config/example.env index b2ad9c716..243d1102d 100644 --- a/config/example.env +++ b/config/example.env @@ -227,3 +227,7 @@ MORDOR_ETC_TESTNET_NODE_HTTP_URL=https://rpc.mordor.etccooperative.org # This is the address behind donation.eth MATCHING_FUND_DONATIONS_FROM_ADDRESS=0x6e8873085530406995170Da467010565968C7C62 QF_ROUND_MAX_REWARD=0.2 + +# Rate limit config +DISABLE_SERVER_RATE_LIMITER=false + diff --git a/config/test.env b/config/test.env index f6ae2fd5d..3307239b5 100644 --- a/config/test.env +++ b/config/test.env @@ -192,4 +192,7 @@ MORDOR_ETC_TESTNET_SCAN_API_URL=https://etc-mordor.blockscout.com/api/v1 # This is the address behind donation.eth MATCHING_FUND_DONATIONS_FROM_ADDRESS=0x6e8873085530406995170Da467010565968C7C62 +# Rate Limit config +DISABLE_SERVER_RATE_LIMITER=false + diff --git a/src/server/bootstrap.ts b/src/server/bootstrap.ts index dfc7a48e9..bef00112d 100644 --- a/src/server/bootstrap.ts +++ b/src/server/bootstrap.ts @@ -234,28 +234,32 @@ export async function bootstrap() { app.use(setI18nLocaleForRequest); // accept-language header app.use(cors(corsOptions)); app.use(bodyParserJson); - const limiter = new RateLimit({ - store: new RedisStore({ - prefix: 'rate-limit:', - client: redis, - // see Configuration - }), - windowMs: 60 * 1000, // 1 minutes - max: Number(process.env.ALLOWED_REQUESTS_PER_MINUTE), // limit each IP to 40 requests per windowMs - skip: (req: Request, res: Response) => { - const vercelKey = process.env.VERCEL_KEY; - if (vercelKey && req.headers.vercel_key === vercelKey) { - // Skip rate-limit for Vercel requests because our front is SSR - return true; - } - if (req.url.startsWith('/admin')) { - // Bypass AdminJS panel request - return true; - } - return false; - }, - }); - app.use(limiter); + + if (process.env.DISABLE_SERVER_RATE_LIMITER !== 'true') { + const limiter = new RateLimit({ + store: new RedisStore({ + prefix: 'rate-limit:', + client: redis, + // see Configuration + }), + windowMs: 60 * 1000, // 1 minutes + max: Number(process.env.ALLOWED_REQUESTS_PER_MINUTE), // limit each IP to 40 requests per windowMs + skip: (req: Request, res: Response) => { + const vercelKey = process.env.VERCEL_KEY; + if (vercelKey && req.headers.vercel_key === vercelKey) { + // Skip rate-limit for Vercel requests because our front is SSR + return true; + } + if (req.url.startsWith('/admin')) { + // Bypass AdminJS panel request + return true; + } + return false; + }, + }); + app.use(limiter); + } + app.use( '/graphql', json({