-
-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into faizan07/issue203
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { NextRequest } from 'next/server'; | ||
import { Ratelimit } from '@upstash/ratelimit'; | ||
import { Redis } from '@upstash/redis'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
const redis = new Redis({ | ||
url: 'https://eternal-deer-42544.upstash.io', | ||
token: process.env['UPSTASH_TOKEN']!, | ||
}); | ||
|
||
const ratelimit = new Ratelimit({ | ||
redis: redis, | ||
limiter: Ratelimit.slidingWindow(5, '10 s'), | ||
}); | ||
|
||
export default async function middleware( | ||
request: NextRequest, | ||
): Promise<Response | undefined> { | ||
const ip = request.ip ?? '127.0.0.1'; | ||
const { success } = await ratelimit.limit(ip); | ||
return success | ||
? NextResponse.next() | ||
: NextResponse.redirect(new URL('/blocked', request.url)); | ||
} | ||
|
||
export const config = { | ||
matcher: '/api/:path*', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type NextPage } from 'next'; | ||
|
||
const Blocked: NextPage = () => { | ||
return ( | ||
<main className="container mx-auto flex min-h-screen flex-col items-center justify-center gap-3 text-center"> | ||
<h1 className="text-6xl font-extrabold tracking-tighter md:text-7xl"> | ||
Access Denied | ||
</h1> | ||
<p className="text-gray-11 dark:text-graydark-11"> | ||
Our servers have put you on the naughty list. | ||
</p> | ||
</main> | ||
); | ||
}; | ||
|
||
export default Blocked; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.