diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-03-24 22:29:45 -0500 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-03-24 22:29:45 -0500 |
commit | 859e14a96e1885b814eb99f1c5a9beb8adfdb591 (patch) | |
tree | 0d88524adc19bb093307ef345b182e3a88f97981 /src | |
parent | cc0b5170fa591dfc0b3c4856d6114893c48d89f7 (diff) | |
download | skyblock-api-859e14a96e1885b814eb99f1c5a9beb8adfdb591.tar.gz skyblock-api-859e14a96e1885b814eb99f1c5a9beb8adfdb591.tar.bz2 skyblock-api-859e14a96e1885b814eb99f1c5a9beb8adfdb591.zip |
add ratelimits to skyblock-api
Diffstat (limited to 'src')
-rw-r--r-- | src/index.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/index.ts b/src/index.ts index edef374..fbab327 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,19 +1,23 @@ import { fetchMemberProfile, fetchUser } from './hypixel' import express from 'express' import { fetchAllLeaderboardsCategorized, fetchMemberLeaderboard } from './database' +import rateLimit from 'express-rate-limit' const app = express() export const debug = false - -app.use((req: express.Request, 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() +// 250 requests over 5 minutes +const limiter = rateLimit({ + windowMs: 60 * 1000 * 5, + max: 250, + skip: (req: express.Request, res) => { + return req.headers.key === process.env.key + } }) +app.use(limiter) + app.get('/', async(req, res) => { res.json({ ok: true }) }) |