Skip to content

Commit

Permalink
rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 8, 2025
1 parent b6819d0 commit d1704b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const server = http.createServer(async (req, res) => {
};
const ip = req.headers['x-forwarded-for'] ||
req.socket.remoteAddress;
// if (ip && await limited(ip)) {
// 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 @@ -37,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
1 change: 1 addition & 0 deletions src/rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const redis = createClient({
redis.on('error', err => console.log('Redis Client Error', err));

const limited = async ip => {
return false;
const key = `rateLimit:${ip}`
const reqLimit = 100;
if (!redis.isReady) await redis.connect();
Expand Down

0 comments on commit d1704b6

Please sign in to comment.