Skip to content

Commit dc04759

Browse files
committed
merge: resolve merge conflict in loadtest-public-api.js
2 parents 5f6e411 + 9e7aa68 commit dc04759

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

apps/public-api/src/middlewares/api_usage.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const rateLimit = require('express-rate-limit');
22
const { Log, redis, ApiAnalytics, getDayKey, DEFAULT_DAILY_TTL_SECONDS, incrWithTtlAtomic } = require('@urbackend/common');
33

44
// Rate Limiter
5-
const limiter = rateLimit({
5+
const rateLimiterMiddleware = rateLimit({
66
windowMs: 15 * 60 * 1000,
7-
max: 100,
7+
max: parseInt(process.env.RATE_LIMIT_MAX || '100', 10),
88
message: { error: "Too many requests, please try again later." },
99
standardHeaders: true,
1010
legacyHeaders: false,
@@ -14,6 +14,14 @@ const limiter = rateLimit({
1414
}
1515
});
1616

17+
const limiter = (req, res, next) => {
18+
const bypassKey = process.env.LOADTEST_BYPASS_KEY || 'urbackend_loadtest_secret';
19+
if (req.headers['x-bypass-rate-limit'] === bypassKey || process.env.BYPASS_RATE_LIMIT === 'true') {
20+
return next();
21+
}
22+
return rateLimiterMiddleware(req, res, next);
23+
};
24+
1725
// Logger with API analytics
1826
const logger = (req, res, next) => {
1927
// Capture start time for response time measurement

scripts/loadtest-public-api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ async function runBenchmark(name, opts) {
4747
method: opts.method || 'GET',
4848
connections,
4949
duration,
50-
headers: opts.headers || {},
50+
headers: {
51+
'x-bypass-rate-limit': process.env.LOADTEST_BYPASS_KEY || 'urbackend_loadtest_secret',
52+
...(opts.headers || {}),
53+
},
5154
body: opts.body ? JSON.stringify(opts.body) : undefined,
5255
},
5356
(err, result) => {

0 commit comments

Comments
 (0)