From dded61a97c602096dd139f567b53b70bc6c4544f Mon Sep 17 00:00:00 2001 From: Juan Manuel Servera <8036360+jmservera@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:11:20 +0200 Subject: [PATCH] chore: Apply rate limiter to all requests in server.js (#6) --- ai/copilot/contoso-real-state-plugin/server.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ai/copilot/contoso-real-state-plugin/server.js b/ai/copilot/contoso-real-state-plugin/server.js index 0661750..2727f34 100644 --- a/ai/copilot/contoso-real-state-plugin/server.js +++ b/ai/copilot/contoso-real-state-plugin/server.js @@ -5,6 +5,16 @@ import cors from "cors"; const app = express(); +// set up rate limiter: maximum of five requests per minute +var RateLimit = require('express-rate-limit'); +var limiter = RateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // max 100 requests per windowMs +}); + +// apply rate limiter to all requests +app.use(limiter); + //add logging to app app.use((req, res, next) => { console.log(`${req.method} request for ${req.url}`);