Skip to content

Commit 45bf757

Browse files
committed
feat: add custom rate limit types
1 parent 3d2a6a6 commit 45bf757

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/function/v2.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ export type { Context } from '@netlify/serverless-functions-api'
33
type Path = `/${string}`
44
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
55
type CronSchedule = string
6+
type RateLimitAlgorithm = 'sliding_window'
7+
type RateLimitAggregator = 'domain' | 'ip'
8+
type RateLimitAction = 'rate_limit' | 'rewrite'
9+
10+
interface RateLimitConfig {
11+
action?: RateLimitAction
12+
aggregateBy?: RateLimitAggregator | RateLimitAggregator[]
13+
algorithm?: RateLimitAlgorithm
14+
to?: string
15+
windowSize: number
16+
}
617

718
interface BaseConfig {
819
/**
@@ -16,6 +27,8 @@ interface BaseConfig {
1627
* function will run for all supported methods.
1728
*/
1829
method?: HTTPMethod | HTTPMethod[]
30+
31+
rateLimit?: RateLimitConfig
1932
}
2033

2134
interface ConfigWithPath extends BaseConfig {

0 commit comments

Comments
 (0)