Skip to content

Commit

Permalink
Added rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiochimera committed Jul 9, 2024
1 parent c11fa5f commit 2a13377
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions alexa/alexa-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = function (RED) {
const util = require('util');
const TokenGenerator = require('uuid-token-generator');
const express = require('express');
const expressRateLimit = require("express-rate-limit");
const helmet = require('helmet');
const morgan = require('morgan');
const cors = require('cors');
Expand Down Expand Up @@ -260,7 +261,15 @@ module.exports = function (RED) {
const node = this;
if (node.verbose) node._debug("startServer port " + node.http_port);
const app = express();
const rate_limit = 30;
const rateLimitMiddleware = expressRateLimit({
windowMs: 60 * 1000,
max: rate_limit,
message: `You have exceeded your ${rate_limit} requests per minute limit.`,
headers: true,
});
app.disable('x-powered-by');
app.use(rateLimitMiddleware);
app.use(helmet());
app.use(cors());
app.use(morgan('dev'));
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-alexa-virtual-smarthome",
"version": "0.0.35",
"version": "0.0.36",
"description": "Node Red Alexa Smarthome node",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -48,6 +48,7 @@
"ask-sdk-model": "^1.86.0",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-rate-limiter": "^1.3.1",
"helmet": "^7.1.0",
"morgan": "^1.10.0",
"stoppable": "^1.1.0",
Expand Down

0 comments on commit 2a13377

Please sign in to comment.