aboutsummaryrefslogtreecommitdiff
path: root/build/index.js
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-03-24 22:34:59 -0500
committermat <27899617+mat-1@users.noreply.github.com>2021-03-24 22:34:59 -0500
commit84cfaf24633351964315ffac0eacb9ed09fd0e94 (patch)
tree7e3f7c8c214b47e2ca5c5a640c5949e2c028b22e /build/index.js
parentac38c2c61dd17bd5324ab98ed5dcc7e1bfd6c754 (diff)
downloadskyblock-api-84cfaf24633351964315ffac0eacb9ed09fd0e94.tar.gz
skyblock-api-84cfaf24633351964315ffac0eacb9ed09fd0e94.tar.bz2
skyblock-api-84cfaf24633351964315ffac0eacb9ed09fd0e94.zip
Update index.js
Diffstat (limited to 'build/index.js')
-rw-r--r--build/index.js18
1 files 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 });
});