Browse Source

🔑 Add rate limiter

main
Haris Razis 4 years ago
parent
commit
fe05bd9ca5
  1. 6
      server/index.js
  2. 11
      server/package-lock.json
  3. 1
      server/package.json

6
server/index.js

@ -4,6 +4,7 @@ const bodyParser = require('body-parser');
const chalk = require('chalk') const chalk = require('chalk')
const cors = require('cors') const cors = require('cors')
const history = require('connect-history-api-fallback'); const history = require('connect-history-api-fallback');
const rateLimit = require('express-rate-limit');
require('./services/socket')(server); require('./services/socket')(server);
require('./connections/mongo_conn'); require('./connections/mongo_conn');
@ -21,6 +22,11 @@ app.use(cors(
} }
)); ));
app.use(rateLimit({
windowMs: 15 * 60 * 1000,
max: 100
}));
app.use(bodyParser.urlencoded({ app.use(bodyParser.urlencoded({
extended: true extended: true
})); }));

11
server/package-lock.json

@ -17,6 +17,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"debug": "^2.6.9", "debug": "^2.6.9",
"express": "^4.17.1", "express": "^4.17.1",
"express-rate-limit": "^5.2.3",
"express-session": "^1.17.1", "express-session": "^1.17.1",
"express-validator": "^6.8.0", "express-validator": "^6.8.0",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",
@ -874,6 +875,11 @@
"node": ">= 0.10.0" "node": ">= 0.10.0"
} }
}, },
"node_modules/express-rate-limit": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.3.tgz",
"integrity": "sha512-cjQH+oDrEPXxc569XvxhHC6QXqJiuBT6BhZ70X3bdAImcnHnTNMVuMAJaT0TXPoRiEErUrVPRcOTpZpM36VbOQ=="
},
"node_modules/express-session": { "node_modules/express-session": {
"version": "1.17.1", "version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",
@ -3462,6 +3468,11 @@
"vary": "~1.1.2" "vary": "~1.1.2"
} }
}, },
"express-rate-limit": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.3.tgz",
"integrity": "sha512-cjQH+oDrEPXxc569XvxhHC6QXqJiuBT6BhZ70X3bdAImcnHnTNMVuMAJaT0TXPoRiEErUrVPRcOTpZpM36VbOQ=="
},
"express-session": { "express-session": {
"version": "1.17.1", "version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",

1
server/package.json

@ -19,6 +19,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"debug": "^2.6.9", "debug": "^2.6.9",
"express": "^4.17.1", "express": "^4.17.1",
"express-rate-limit": "^5.2.3",
"express-session": "^1.17.1", "express-session": "^1.17.1",
"express-validator": "^6.8.0", "express-validator": "^6.8.0",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",

Loading…
Cancel
Save