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.

566 B
Raw Blame
import { ratelimit } from "../upstash";

export async function rateLimitRequest({
  identifier,
  requests,
  interval,
}: {
  identifier: string;
  requests: number;
  interval: `${number} s` | `${number} m`;
}) {
  const { success, limit, reset, remaining } = await ratelimit(
    requests,
    interval,
  ).limit(identifier);

  return {
    success,
    headers: {
      "Retry-After": reset.toString(),
      "X-RateLimit-Limit": limit.toString(),
      "X-RateLimit-Remaining": remaining.toString(),
      "X-RateLimit-Reset": reset.toString(),
    },
  };
}