ADD: rate limiting
This commit is contained in:
parent
995374ff48
commit
0f423817c3
@ -57,7 +57,6 @@ const rateLimit = require('express-rate-limit');
|
|||||||
const postLimiter = rateLimit({
|
const postLimiter = rateLimit({
|
||||||
windowMs: 30 * 60 * 1000,
|
windowMs: 30 * 60 * 1000,
|
||||||
max: 50,
|
max: 50,
|
||||||
message: 'You are going too fast',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/create', postLimiter, async function(req, res) {
|
router.post('/create', postLimiter, async function(req, res) {
|
||||||
|
10
index.js
10
index.js
@ -14,6 +14,14 @@ morgan.token('id', function getId(req) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let app = express();
|
let app = express();
|
||||||
|
app.enable('trust proxy');
|
||||||
|
|
||||||
|
const rateLimit = require('express-rate-limit');
|
||||||
|
const limiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000,
|
||||||
|
max: 100,
|
||||||
|
});
|
||||||
|
app.use(limiter);
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
req.id = uuid.v4();
|
req.id = uuid.v4();
|
||||||
@ -26,8 +34,6 @@ app.use(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
app.set('trust proxy', 'loopback');
|
|
||||||
|
|
||||||
let bodyParser = require('body-parser');
|
let bodyParser = require('body-parser');
|
||||||
let config = require('./config');
|
let config = require('./config');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user