Skip to content

Commit

Permalink
reintroduce rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 8, 2025
1 parent 5fb95fb commit 76cf553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 4 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ const server = http.createServer(async (req, res) => {
};
const ip = req.headers['x-forwarded-for'] ||
req.socket.remoteAddress;
// if (ip && await limited(ip)) {
// console.log('limited')
// res.writeHead(429, headers);
// } else {
if (ip && await limited(ip)) {
res.writeHead(429, headers);
} else {
res.writeHead(200, headers);
if (req.url === '/asset_prices') {
res.end(JSON.stringify(await getPrices()));
Expand All @@ -38,7 +37,7 @@ const server = http.createServer(async (req, res) => {
} else if (supplyAddress(req.url)) {
res.end(JSON.stringify(await getSupplyData(req.url)))
}
// }
}

res.end();
});
Expand Down
2 changes: 0 additions & 2 deletions src/rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const limited = async ip => {
const key = `rateLimit:${ip}`
const reqLimit = 100;
if (!redis.isReady) await redis.connect();
console.log(redis.isReady);
const visits = await redis.INCR(key);
console.log(visits)
if (visits === 1) await redis.EXPIRE(key, 60);
await redis.disconnect();
return visits > reqLimit;
Expand Down

0 comments on commit 76cf553

Please sign in to comment.