qavi
qavi
CDCloudflare Developers
Created by qavi on 6/24/2024 in #workers-help
Rate Limiting
How can I set duration, like for 5 minutes the user should be rate limitted when Rate Limitting.
// Rate limitting
const clientIP = request.headers.get('cf-connecting-ip');
const { success } = await env.RATE_LIMITER.limit({ key: clientIP || '' }); // key can be any string of your choosing
if (!success) {
// Return 403 Forbidden for disallowed origins
console.log(clientIP, success);

return new Response(`429 Failure – rate limit exceeded`, { status: 429 });
}
// Rate limitting
const clientIP = request.headers.get('cf-connecting-ip');
const { success } = await env.RATE_LIMITER.limit({ key: clientIP || '' }); // key can be any string of your choosing
if (!success) {
// Return 403 Forbidden for disallowed origins
console.log(clientIP, success);

return new Response(`429 Failure – rate limit exceeded`, { status: 429 });
}
2 replies