favo
favo
CDCloudflare Developers
Created by favo on 7/10/2024 in #workers-help
Rate Limit not limitting
I have a simple worker that reads an API Key from D1 and shall use the rate limitter to apply limits to it. I've configured a very small limit in my config to test it:
[[unsafe.bindings]]
name = "RPC_LIMITER"
type = "ratelimit"
namespace_id = "1"
simple = { limit = 1, period = 60 }
[[unsafe.bindings]]
name = "RPC_LIMITER"
type = "ratelimit"
namespace_id = "1"
simple = { limit = 1, period = 60 }
and I wanted to test the limit, it was not applied. Even calling it with a hard coded key does not limit it in my tests:
const limit = await env.RPC_LIMITER.limit({ key: "apiKey.userId" })
const { success } = limit
if (!success) {
return new Response(`429 Failure – rate limit exceeded for ${apiKey.userId}`, { status: 429 })
}
const limit = await env.RPC_LIMITER.limit({ key: "apiKey.userId" })
const { success } = limit
if (!success) {
return new Response(`429 Failure – rate limit exceeded for ${apiKey.userId}`, { status: 429 })
}
Am I missing something? It seems like the limitter is not incrementing. Thanks a lot, in advance, for any help!
9 replies