From be345e3d3418c96a44961e4771d2a2c1234e40dd Mon Sep 17 00:00:00 2001 From: Bobby Date: Fri, 15 Apr 2022 14:15:32 +0700 Subject: [PATCH] fix: align with express-rate-limit v6 --- config.sample.js | 12 ++++++++++-- lolisafe.js | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config.sample.js b/config.sample.js index 22198e3..89be37c 100644 --- a/config.sample.js +++ b/config.sample.js @@ -161,7 +161,7 @@ module.exports = { /* Rate limits. Please be aware that these apply to all users, including site owners. - https://github.com/nfriedly/express-rate-limit#configuration-options + https://github.com/nfriedly/express-rate-limit#usage */ rateLimits: [ { @@ -172,6 +172,8 @@ module.exports = { config: { windowMs: 1000, max: 10, + legacyHeaders: true, + standardHeaders: true, message: { success: false, description: 'Rate limit reached, please try again in a while.' @@ -187,6 +189,8 @@ module.exports = { config: { windowMs: 5 * 1000, max: 2, + legacyHeaders: true, + standardHeaders: true, message: { success: false, description: 'Rate limit reached, please try again in 5 seconds.' @@ -200,7 +204,9 @@ module.exports = { ], config: { windowMs: 30 * 1000, - max: 6 + max: 6, + legacyHeaders: true, + standardHeaders: true } }, { @@ -211,6 +217,8 @@ module.exports = { config: { windowMs: 60 * 1000, max: 1, + legacyHeaders: true, + standardHeaders: true, message: { success: false, description: 'Rate limit reached, please try again in 60 seconds.' diff --git a/lolisafe.js b/lolisafe.js index 0df7658..21b52c0 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -17,7 +17,7 @@ const express = require('express') const helmet = require('helmet') const nunjucks = require('nunjucks') const path = require('path') -const RateLimit = require('express-rate-limit') +const rateLimit = require('express-rate-limit') const readline = require('readline') const serveStatic = require('@bobbywibowo/serve-static') const { accessSync, constants } = require('fs') @@ -83,9 +83,9 @@ safe.enable('view cache') // Configure rate limits if (Array.isArray(config.rateLimits) && config.rateLimits.length) { - for (const rateLimit of config.rateLimits) { - const limiter = new RateLimit(rateLimit.config) - for (const route of rateLimit.routes) { + for (const _rateLimit of config.rateLimits) { + const limiter = rateLimit(_rateLimit.config) + for (const route of _rateLimit.routes) { safe.use(route, limiter) } }