add exclusion list

This commit is contained in:
Aidan 2024-12-03 22:53:10 -05:00
parent f3bcddcfa7
commit ec81f3ccd7
2 changed files with 10 additions and 0 deletions

4
app.js
View File

@ -3,6 +3,7 @@ const bodyParser = require('body-parser');
const path = require('path');
const winston = require('winston');
const rateLimit = require('express-rate-limit');
const fs = require('fs');
const logger = winston.createLogger({
level: 'info',
@ -17,12 +18,15 @@ const logger = winston.createLogger({
],
});
const exclusions = JSON.parse(fs.readFileSync('exclusions.json', 'utf8')).excludedIPs;
const registerLimiter = rateLimit({
windowMs: 24 * 60 * 60 * 1000,
max: 1,
message: 'You have already submitted a registration today. Please try again tomorrow.',
standardHeaders: true,
legacyHeaders: false,
skip: (req, res) => exclusions.includes(req.ip)
});
const app = express();

6
exclusions.json.example Normal file
View File

@ -0,0 +1,6 @@
{
"excludedIPs": [
"127.0.0.1",
"192.168.1.1"
]
}