sveltekit-rate-limiter
sveltekit-rate-limiter copied to clipboard
[Enhancement] A collection of pre-included plugins
What do you think about the potential of having some premade plugins included in the library? For example, if people are serving their website via CF or another reverse proxy, the clients' IP addresses are obscured and so you have to use the CF-Connecting-IP header, otherwise then you just end up ratelimiting CF's IP (e.g., every single user who wants to access that endpoint is now ratelimited).
export class CloudflareRateLimiter implements RateLimiterPlugin {
readonly rate: Rate;
constructor(rate: { limit: number, duration: RateUnit }) {
this.rate = [rate.limit, rate.duration];
}
async hash(event: RequestEvent) {
return event.request.headers.get('cf-connecting-ip') || event.getClientAddress();
}
}