({
rateLimitId,
rateLimitKey,
}: {
rateLimitId: string;
rateLimitKey?: string;
})
| 42 | } |
| 43 | |
| 44 | async function check({ |
| 45 | rateLimitId, |
| 46 | rateLimitKey, |
| 47 | }: { |
| 48 | rateLimitId: string; |
| 49 | rateLimitKey?: string; |
| 50 | }): Promise<LimitResult> { |
| 51 | const requestHeaders = await getRequestHeaders(); |
| 52 | const { rateLimited, error } = await checkRateLimit(rateLimitId, { |
| 53 | headers: requestHeaders, |
| 54 | rateLimitKey, |
| 55 | firewallHostForDevelopment, |
| 56 | }); |
| 57 | |
| 58 | // We deliberately fail open on misconfiguration: a missing dashboard rule |
| 59 | // shouldn't lock out every user (worse than no rate limit). But silent |
| 60 | // fail-open is dangerous, so surface it loudly so it's caught in |
| 61 | // production logs / alerting instead of going unnoticed. |
| 62 | if (error === "not-found") { |
| 63 | console.error( |
| 64 | `[rate-limit] Vercel Firewall rule '${rateLimitId}' is not configured. Rate limiting is DISABLED for this rule until the rule is created in the Firewall dashboard.`, |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | return { success: !rateLimited }; |
| 69 | } |
| 70 | |
| 71 | export async function installPerPluginLimit( |
| 72 | pluginId: string, |
no test coverage detected