Skip to content

Commit

Permalink
Added a rate limiter to Express Server
Browse files Browse the repository at this point in the history
  • Loading branch information
IGuy37 committed Jul 8, 2024
1 parent 497493e commit 2ef19f5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const PORT = 3000;
app.use(express.json());
app.use(cors());

// set up rate limiter: maximum of 60 requests per minute
const RateLimit = require('express-rate-limit');
const limiter = RateLimit({
windowMs: 60 * 1000, // 1 minute
max: 60, // max 5 requests per windowMs
});

// apply rate limiter to all requests
app.use(limiter);

app.post('/socks', async (req, res) => {
try {
const client = await MongoClient.connect(url);
Expand Down

0 comments on commit 2ef19f5

Please sign in to comment.