Skip to content

Commit

Permalink
disable ratelimiter from env (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 authored Dec 22, 2023
1 parent e0ec480 commit c04c7c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
4 changes: 4 additions & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 3 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -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


48 changes: 26 additions & 22 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit c04c7c1

Please sign in to comment.