Skip to content

Commit

Permalink
Merge pull request #72 from Kinfe123/feat/ratelimit
Browse files Browse the repository at this point in the history
fix: add ratelimter
  • Loading branch information
Kinfe123 committed Jun 22, 2024
2 parents 803aa07 + 3728a14 commit 183ed05
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 8 deletions.
1 change: 0 additions & 1 deletion apps/www/app/(www)/login/_components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default function FUILoginWithGridProvider() {
</button>
<button
disabled={true}

onMouseEnter={() => setReset(false)}
onMouseLeave={() => setReset(true)}
className="group flex transform-gpu bg-page-gradient bg-page-gradient dark:[border:1px_solid_rgba(255,255,255,.1)] dark:[box-shadow:0_-20px_80px_-20px_#8686f01f_inset] border-white/10 items-center justify-center py-5 border rounded-lg hover:bg-transparent/50 duration-150 active:bg-transparent/50"
Expand Down
17 changes: 17 additions & 0 deletions apps/www/app/api/limiter/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ratelimit } from "utils/ratelimit";
export async function POST(req: Request) {
try {
const res = await req.json();
const ip = req.headers.get("x-forwarded-for") ?? "";
const data = await ratelimit.limit(ip);
if (!data.success) {
return new Response("You can only send 1 req / 30min.", {
status: 429,
});
}
return new Response("The data logged: " + JSON.stringify(res));
} catch (err) {
console.log("Error has occured ", err);
return new Response("Error has occured", { status: 404 });
}
}
Empty file removed apps/www/middlewware.ts
Empty file.
13 changes: 6 additions & 7 deletions apps/www/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('next').NextConfig} */
import {withContentlayer} from "next-contentlayer"
import { withContentlayer } from "next-contentlayer";
const nextConfig = {
// async rewrites() {
// return [
Expand All @@ -13,7 +13,9 @@ const nextConfig = {
DATABASE_URL: process.env.DATABASE_URL,
COMPONENT_REGISTERY_API_URL: process.env.COMPONENT_REGISTERY_API_URL,
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL,
UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN,
},
images: {
remotePatterns: [
Expand Down Expand Up @@ -41,11 +43,8 @@ const nextConfig = {
protocol: "https",
hostname: "github.com",
},

],
},


},
};

export default withContentlayer(nextConfig)
export default withContentlayer(nextConfig);
2 changes: 2 additions & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@tailwindcss/typography": "^0.5.0",
"@types/babel__core": "^7.1.19",
"@upstash/ratelimit": "^1.2.1",
"@upstash/redis": "^1.31.6",
"@usermaven/sdk-js": "^1.1.9",
"@vercel/analytics": "^1.2.2",
"axios": "^0.24.0",
Expand Down
13 changes: 13 additions & 0 deletions apps/www/utils/ratelimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Ratelimit } from "@upstash/ratelimit"
import { Redis } from "@upstash/redis"
export const db: Redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!
});

export const ratelimit = new Ratelimit({
redis: db,
limiter: Ratelimit.slidingWindow(1, "30 m")

})

Empty file modified packages/cli/dist/index.js
100644 → 100755
Empty file.
29 changes: 29 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 183ed05

Please sign in to comment.