Skip to content

Commit

Permalink
Merge branch 'main' into faizan07/issue203
Browse files Browse the repository at this point in the history
  • Loading branch information
ixahmedxi authored Jul 9, 2023
2 parents 8108686 + a1840a8 commit af3ead2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@trpc/next": "^10.34.0",
"@trpc/react-query": "^10.34.0",
"@trpc/server": "^10.34.0",
"@upstash/ratelimit": "^0.4.3",
"@vercel/analytics": "^1.0.1",
"lucide-react": "^0.259.0",
"next": "13.4.9",
Expand Down
28 changes: 28 additions & 0 deletions apps/web/src/middleware.ts
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*',
};
16 changes: 16 additions & 0 deletions apps/web/src/pages/blocked.tsx
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;
2 changes: 1 addition & 1 deletion apps/web/src/pages/waitlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const WaitList: NextPage = () => {
<p className="text-gray-11 dark:text-graydark-11 mx-auto text-center">
<Balancer>
By signing up to our waitlist, you will be first in line to know
when we launch and geting early access.
when we launch and getting early access.
</Balancer>
</p>
<form
Expand Down
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af3ead2

Please sign in to comment.