From 84cfaf24633351964315ffac0eacb9ed09fd0e94 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Wed, 24 Mar 2021 22:34:59 -0500 Subject: Update index.js --- build/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/build/index.js b/build/index.js index 11b2fc6..536b43e 100644 --- a/build/index.js +++ b/build/index.js @@ -7,14 +7,22 @@ exports.debug = void 0; const hypixel_1 = require("./hypixel"); const express_1 = __importDefault(require("express")); const database_1 = require("./database"); +const express_rate_limit_1 = __importDefault(require("express-rate-limit")); const app = express_1.default(); exports.debug = false; -app.use((req, res, next) => { - if (process.env.key && req.headers.key !== process.env.key) - // if a key is set in process.env and the header doesn't match return an error - return res.status(401).json({ error: 'Key in header must match key in env' }); - next(); +// 500 requests over 5 minutes +const limiter = express_rate_limit_1.default({ + windowMs: 60 * 1000 * 5, + max: 500, + skip: (req) => { + return req.headers.key === process.env.key; + }, + keyGenerator: (req) => { + var _a; + return ((_a = req.headers['Cf-Connecting-Ip']) !== null && _a !== void 0 ? _a : req.ip).toString(); + } }); +app.use(limiter); app.get('/', async (req, res) => { res.json({ ok: true }); }); -- cgit