Skip to content

Commit 00e262a

Browse files
authoredMay 16, 2024··
feat: add custom rate limit types (#500)
Base types for custom rate limit config type inference (almost forgot). Basically a dried out version of https://github.com/netlify/zip-it-and-ship-it/blob/main/src/rate_limit.ts, but let me know if you think I should just use the original one instead. Related to ADN-294 Will do the same for edge-functions after this one gets through
1 parent 3d2a6a6 commit 00e262a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

‎src/function/v2.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ 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 RateLimitAggregator = 'domain' | 'ip'
7+
type RateLimitAction = 'rate_limit' | 'rewrite'
8+
9+
interface RateLimitConfig {
10+
action?: RateLimitAction
11+
aggregateBy?: RateLimitAggregator | RateLimitAggregator[]
12+
to?: string
13+
windowSize: number
14+
}
615

716
interface BaseConfig {
817
/**
@@ -16,6 +25,8 @@ interface BaseConfig {
1625
* function will run for all supported methods.
1726
*/
1827
method?: HTTPMethod | HTTPMethod[]
28+
29+
rateLimit?: RateLimitConfig
1930
}
2031

2132
interface ConfigWithPath extends BaseConfig {

0 commit comments

Comments
 (0)
Please sign in to comment.