express rate limit
This commit is contained in:
Generated
+6
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitblog.md",
|
||||
"version": "1.2.6",
|
||||
"version": "1.2.7",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -3130,6 +3130,11 @@
|
||||
"vary": "~1.1.2"
|
||||
}
|
||||
},
|
||||
"express-rate-limit": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.0.0.tgz",
|
||||
"integrity": "sha512-dhT57wqxfqmkOi4HM7NuT4Gd7gbUgSK2ocG27Y6lwm8lbOAw9XQfeANawGq8wLDtlGPO1ZgDj0HmKsykTxfFAg=="
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"crypto": "^1.0.1",
|
||||
"ejs": "^2.6.2",
|
||||
"express": "^4.17.1",
|
||||
"express-rate-limit": "^5.0.0",
|
||||
"fa-diagrams": "^1.0.3",
|
||||
"mathjax-node": "^2.1.1",
|
||||
"ncp": "^2.0.0",
|
||||
|
||||
@@ -3,6 +3,7 @@ const app = express();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const pjson = require('../package.json');
|
||||
const rateLimit = require('express-rate-limit');
|
||||
|
||||
app.enable('trust proxy');
|
||||
|
||||
@@ -122,6 +123,13 @@ module.exports = (config) => {
|
||||
next();
|
||||
});
|
||||
|
||||
//rate limit for safer server
|
||||
const limiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: config['rate_limit']
|
||||
});
|
||||
app.use(limiter);
|
||||
|
||||
//log request at result end
|
||||
app.use((req, res, next) => {
|
||||
if (config['access_log']) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"host": "",
|
||||
"data_dir": "data",
|
||||
"view_engine": "ejs",
|
||||
"rate_limit": 100,
|
||||
"access_log": "access.log",
|
||||
"error_log": "error.log",
|
||||
"modules": {
|
||||
|
||||
Reference in New Issue
Block a user