Skip to content

Commit

Permalink
fix(NEXT): rate limit issues fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
arg0WAK committed Jun 8, 2024
1 parent 16b8914 commit d9204ae
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ app.use(express.urlencoded({ extended: true }));

swagger(app);

app.use(limiter);

const PORT = env.PORT;

app.listen(PORT, () => {
Expand All @@ -26,19 +24,23 @@ app.listen(PORT, () => {
});

app.use((req, res, next) => {
if (req.url === "/any") {
if (req.url === "/any" || req.url === "/health") {
return next();
} else {
limiter(req, res, (err) => {
if (err) {
return next(err);
}
console.log(`
${colors.info}Rate Limit:${colors.reset}
${colors.debug} Limit: ${colors.warning}${req.rateLimit.limit}${colors.reset}
${colors.debug} Used: ${colors.warning}${req.rateLimit.used}${colors.reset}
${colors.debug} Remaining: ${colors.warning}${req.rateLimit.remaining}${colors.reset}
${colors.debug} Reset Time: ${colors.warning}${req.rateLimit.resetTime}${colors.reset}
`);
next();
});
}

console.log(`
${colors.info}Rate Limit:${colors.reset}
${colors.debug} Limit: ${colors.warning}${req.rateLimit.limit}${colors.reset}
${colors.debug} Used: ${colors.warning}${req.rateLimit.used}${colors.reset}
${colors.debug} Remaining: ${colors.warning}${req.rateLimit.remaining}${colors.reset}
${colors.debug} Reset Time: ${colors.warning}${req.rateLimit.resetTime}${colors.reset}
`);

next();
});

app.use("/", router);

0 comments on commit d9204ae

Please sign in to comment.