18 lines
526 B
TypeScript
18 lines
526 B
TypeScript
import { env } from '@konobangu/env';
|
|
import { Ratelimit, type RatelimitConfig } from '@upstash/ratelimit';
|
|
import { Redis } from '@upstash/redis';
|
|
|
|
export const redis = new Redis({
|
|
url: env.UPSTASH_REDIS_REST_URL,
|
|
token: env.UPSTASH_REDIS_REST_TOKEN,
|
|
});
|
|
|
|
export const createRateLimiter = (props: Omit<RatelimitConfig, 'redis'>) =>
|
|
new Ratelimit({
|
|
redis,
|
|
limiter: props.limiter ?? Ratelimit.slidingWindow(10, '10 s'),
|
|
prefix: props.prefix ?? 'next-forge',
|
|
});
|
|
|
|
export const { slidingWindow } = Ratelimit;
|