Skip to content

Commit

Permalink
Merge pull request #1143 from OpenEnergyDashboard/dependabot/npm_and_…
Browse files Browse the repository at this point in the history
…yarn/express-rate-limit-7.2.0

Bump express-rate-limit from 5.5.1 to 7.2.0
  • Loading branch information
huss committed May 29, 2024
2 parents e972b43 + 699fda2 commit f6b5b17
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"dotenv": "~16.4.5",
"escape-html": "~1.0.3",
"express": "~4.19.2",
"express-rate-limit": "~5.5.1",
"express-rate-limit": "~7.2.0",
"history": "~4.7.2",
"ini": "~2.0.0",
"jsonschema": "~1.4.1",
Expand Down
19 changes: 13 additions & 6 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,34 @@ const ciks = require('./routes/ciks');

// Limit the rate of overall requests to OED
// Note that the rate limit may make the automatic test return the value of 429. In that case, the limiters below need to be increased.
// TODO Verify that user see the message returned, see https://express-rate-limit.mintlify.app/reference/configuration#message
// Create a limit of 200 requests/5 seconds
const generalLimiter = new rateLimit({
const generalLimiter = rateLimit({
windowMs: 5 * 1000, // 5 seconds
max: 200 // 200 requests
limit: 200, // 200 requests
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false // Disable the `X-RateLimit-*` headers
});
// Apply the limit to overall requests
const app = express().use(generalLimiter);

// This is limiting 3D-Graphic
const threeDLimiter = new rateLimit({
const threeDLimiter = rateLimit({
// TODO This was causing tests to fail for 3D rejection. This limit seems to be okay
// but we should find a better solution than upping values just for tests.
windowMs: 10 * 1000, // 10 seconds
max: 15
limit: 15,
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false // Disable the `X-RateLimit-*` headers
});
app.use('/api/unitReadings/threeD/meters', threeDLimiter);

// Limit the number of raw exports to 5 per 5 seconds
const exportRawLimiter = new rateLimit({
const exportRawLimiter = rateLimit({
windowMs: 5 * 1000, // 5 seconds
max: 5 // 5 requests
limit: 5, // 5 requests
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false // Disable the `X-RateLimit-*` headers
});
// Apply the raw export limit
app.use('/api/readings/line/raw/meters', exportRawLimiter);
Expand Down

0 comments on commit f6b5b17

Please sign in to comment.