Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

edit rate limits

Steven Tey92d08de786ce
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index a9378ccdf2..d2aa503b20 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -20,10 +20,16 @@ export default async function LinkMiddleware(
return NextResponse.next();
}
- const ip = ipAddress(req) || LOCALHOST_IP;
- const { success } = await ratelimit(5, "60 s").limit(ip);
- if (!success) {
- return new Response("Don't DDoS me pls 🥺", { status: 429 });
+ if (domain === "dub.sh") {
+ const ip = ipAddress(req) || LOCALHOST_IP;
+ const { success } = await ratelimit(
+ 5,
+ key === "github" ? "120 s" : "10 s",
+ ).limit(ip);
+
+ if (!success) {
+ return new Response("Don't DDoS me pls 🥺", { status: 429 });
+ }
}
const response = await redis.get<{
diff --git a/pages/api/edge/links/[key]/stats/[endpoint].ts b/pages/api/edge/links/[key]/stats/[endpoint].ts
index bf934cc454..237a1fb739 100644
--- a/pages/api/edge/links/[key]/stats/[endpoint].ts
+++ b/pages/api/edge/links/[key]/stats/[endpoint].ts
@@ -18,10 +18,15 @@ export default async function handler(req: NextRequest) {
let domain = req.nextUrl.hostname;
if (isHomeHostname(domain)) domain = "dub.sh";
- const ip = ipAddress(req) || LOCALHOST_IP;
- const { success } = await ratelimit(5, "60 s").limit(ip);
- if (!success) {
- return new Response("Don't DDoS me pls 🥺", { status: 429 });
+ if (domain === "dub.sh") {
+ const ip = ipAddress(req) || LOCALHOST_IP;
+ const { success } = await ratelimit(
+ 5,
+ key === "github" ? "120 s" : "10 s",
+ ).limit(ip);
+ if (!success) {
+ return new Response("Don't DDoS me pls 🥺", { status: 429 });
+ }
}
let data;