From a2be11558dcae3f6ef6c309082198a70b86e7265 Mon Sep 17 00:00:00 2001 From: Claudio Chimera Date: Sat, 13 Jul 2024 21:29:55 +0200 Subject: [PATCH] Optional Rate Limit --- alexa/alexa-adapter.html | 2 +- alexa/alexa-adapter.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/alexa/alexa-adapter.html b/alexa/alexa-adapter.html index 394ea36..fda7616 100644 --- a/alexa/alexa-adapter.html +++ b/alexa/alexa-adapter.html @@ -22,7 +22,7 @@ } }, rate_limit: { - value: 60, required: false, validate: function (v) { + value: '', required: false, validate: function (v) { if (v === undefined || v.trim().length === 0) return true; const n = parseInt(v); const f = parseFloat(v); diff --git a/alexa/alexa-adapter.js b/alexa/alexa-adapter.js index 7b516ba..c2c3a80 100644 --- a/alexa/alexa-adapter.js +++ b/alexa/alexa-adapter.js @@ -143,7 +143,7 @@ module.exports = function (RED) { node.http_path = node.usehttpnoderoot ? node.Path_join(node.httpNodeRoot, config.http_path || '') : config.http_path || ''; node.http_port = config.port || ''; node.https_server = config.https_server || false; - node.rate_limit = parseInt(config.rate_limit || 60); + node.rate_limit = parseInt(config.rate_limit || '0'); node.http_root = node.Path_join('/', node.http_path.trim()); node.http_server = null; node.user_dir = RED.settings.userDir || '.'; @@ -263,13 +263,15 @@ module.exports = function (RED) { if (node.verbose) node._debug("startServer port " + node.http_port + " rate limit " + node.rate_limit); const app = express(); app.disable('x-powered-by'); - const rateLimitMiddleware = expressRateLimit({ - windowMs: 60 * 1000, - max: node.rate_limit, - message: `You have exceeded your ${node.rate_limit} requests per minute limit.`, - headers: true, - }); - app.use(rateLimitMiddleware); + if (node.rate_limit > 0) { + const rateLimitMiddleware = expressRateLimit({ + windowMs: 60 * 1000, + max: node.rate_limit, + message: `You have exceeded your ${node.rate_limit} requests per minute limit.`, + headers: true, + }); + app.use(rateLimitMiddleware); + } app.use(helmet()); app.use(cors()); app.use(morgan('dev'));