UNPKG

slow-it-down

Version:

A rate limiter for express using a token bucket

41 lines (40 loc) 1.15 kB
import { Netmask } from 'netmask'; import { TokenBucket } from './tokenBucket'; import { TokenStorageEngine } from './tokenTable'; export declare type Maybe<T> = T | undefined; export declare const hasValues: (ip: boolean | undefined, xff: boolean | undefined, user: boolean | undefined) => boolean; export declare const isNetBlock: (mask: Netmask) => boolean; export declare const handleNetmasks: (overrides: any) => any; export interface Overrides { [key: string]: BaseConfiguration; } export interface BaseConfiguration { burst: number; rate: number; ip?: boolean; user?: boolean; xff?: boolean; block?: any; } export declare type Configuration = BaseConfiguration & { tokensTable?: TokenStorageEngine<TokenBucket>; maxKeys?: number; message?: string; overrides?: Overrides; }; /** * Express middleware that requires an Options object containing * at least a burst and rate property. * * @example * throttle({ * burst: 10, * rate: 1, * ip: true, * }) * * @param {Configuration} options * @returns {*} */ declare const slowDown: (config: Configuration) => any; export default slowDown;