Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

feat: add custom rate limit types #500

Merged
merged 2 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/function/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ export type { Context } from '@netlify/serverless-functions-api'
type Path = `/${string}`
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
type CronSchedule = string
type RateLimitAggregator = 'domain' | 'ip'
type RateLimitAction = 'rate_limit' | 'rewrite'

interface RateLimitConfig {
action?: RateLimitAction
aggregateBy?: RateLimitAggregator | RateLimitAggregator[]
to?: string
windowSize: number
}

interface BaseConfig {
/**
Expand All @@ -16,6 +25,8 @@ interface BaseConfig {
* function will run for all supported methods.
*/
method?: HTTPMethod | HTTPMethod[]

rateLimit?: RateLimitConfig
}

interface ConfigWithPath extends BaseConfig {
Expand Down