Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
doyupK committed Jul 3, 2024
1 parent f5457bb commit c871a41
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const rateLimitStore: Record<string, { count: number; timestamp: number }> = {};
async function rateLimiter(req: NextRequest) {
let ip = req.headers.get('x-forwarded-for');
if (!ip) {
ip = req.headers.get('cf-connecting-ip') ||
req.headers.get('x-real-ip') ||
req.headers.get('fastly-client-ip') ||
req.headers.get('True-Client-IP') ||
req.headers.get('x-client-ip') ||
req.headers.get('x-cluster-client-ip') ||
req.ip ||
'unknown';
ip =
req.headers.get('cf-connecting-ip') ||
req.headers.get('x-real-ip') ||
req.headers.get('fastly-client-ip') ||
req.headers.get('True-Client-IP') ||
req.headers.get('x-client-ip') ||
req.headers.get('x-cluster-client-ip') ||
req.ip ||
'unknown';
}

if (blockedIPs[ip]) {
Expand All @@ -37,10 +38,10 @@ async function rateLimiter(req: NextRequest) {
} else {
return NextResponse.json(
{
error: 'Your IP has been temporarily blocked due to excessive requests.'
error: 'Your IP has been temporarily blocked due to excessive requests.',
},
{
status: 403
{
status: 403,
}
);
}
Expand All @@ -59,11 +60,11 @@ async function rateLimiter(req: NextRequest) {
if (rateLimitStore[ip].count > MAX_REQUESTS) {
blockedIPs[ip] = currentTime;
return NextResponse.json(
{
error: 'Too many requests, please try again later.'
{
error: 'Too many requests, please try again later.',
},
{
status: 429
status: 429,
}
);
}
Expand Down

0 comments on commit c871a41

Please sign in to comment.