LibreChat/api/server/middleware/loginLimiter.js
Danny Avila 75be9a3279
feat: bun support 🥟 (#907)
* feat: bun 🥟

* check if playwright/linux workflow is fixed

* fix: backend issues exposed by bun

* feat: update scripts for bun
2023-09-10 16:04:08 -04:00

16 lines
598 B
JavaScript

const rateLimit = require('express-rate-limit');
const windowMs = (process.env?.LOGIN_WINDOW ?? 5) * 60 * 1000; // default: 5 minutes
const max = process.env?.LOGIN_MAX ?? 7; // default: limit each IP to 7 requests per windowMs
const windowInMinutes = windowMs / 60000;
const loginLimiter = rateLimit({
windowMs,
max,
message: `Too many login attempts from this IP, please try again after ${windowInMinutes} minutes.`,
keyGenerator: function (req) {
// Strip out the port number from the IP address
return req.ip.replace(/:\d+[^:]*$/, '');
},
});
module.exports = loginLimiter;