Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions apps/demos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"babel-jest": "29.7.0",
"consola": "3.2.3",
"cookie-parser": "1.4.7",
"express-rate-limit": "8.3.1",
"cross-env": "7.0.3",
"devextreme-screenshot-comparer": "2.0.17",
"eslint": "catalog:",
Expand Down
24 changes: 5 additions & 19 deletions apps/demos/utils/server/csp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const crypto = require('crypto');
const express = require('express');
const rateLimit = require('express-rate-limit');
const serveStatic = require('serve-static');
const cookieParser = require('cookie-parser');
const { join, resolve } = require('path');
Expand Down Expand Up @@ -376,25 +377,10 @@ const demoIndexHandler = (request, response) => {
response.send(fileContent);
};

const createRateLimiter = (windowMs = 60000, maxRequests = 200) => {
const hits = new Map();

setInterval(() => hits.clear(), windowMs);

return (req, res, next) => {
const key = req.ip;
const count = (hits.get(key) || 0) + 1;
hits.set(key, count);

if (count > maxRequests) {
res.status(429).send('Too Many Requests');
return;
}
next();
};
};

const rateLimiter = createRateLimiter();
const rateLimiter = rateLimit({
windowMs: 60 * 1000,
max: 200,
});

const app = express();
app.use(cookieParser());
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

Loading