Skip to content

[Enhancement] A collection of pre-included plugins #12

@conorvenus

Description

@conorvenus

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();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions