File size: 710 Bytes
58379d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Ratelimit } from "@upstash/ratelimit"

import { redis } from "./redis"

// Create a global ratelimiter for all users, that allows 14 requests per 60 seconds
// 14 is roughly the number of requests that can be handled by the server
/*
const rateLimitGlobal = new Ratelimit({
  redis,
  limiter: Ratelimit.slidingWindow(14, "60 s"),
  analytics: true,
  timeout: 1000,
  prefix: "production"
})
*/

// Create a new ratelimiter for anonymous users
export function getRateLimit() {
  const rateLimit = new Ratelimit({
    redis,
    limiter: Ratelimit.slidingWindow(1, "1 m"), // 1 request every minute
    analytics: true,
    // timeout: 120000,
    prefix: "production:anon"
  })

  return rateLimit
}