add IP-based rate limiting to Cloudflare Worker#37
Merged
dineshsutihar merged 2 commits intoStructZ:developfrom Sep 7, 2025
Merged
add IP-based rate limiting to Cloudflare Worker#37dineshsutihar merged 2 commits intoStructZ:developfrom
dineshsutihar merged 2 commits intoStructZ:developfrom
Conversation
Collaborator
|
It looks good from a quick glance. Let me pull it down to my system and verify everything, and then we should be good to merge. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds IP-based rate limiting to protect the Cloudflare Worker's /v1/translate and /v1/explain routes from abuse. The implementation sets a limit of 10 requests per minute per IP address using Cloudflare KV storage.
- Introduces a
checkRateLimitfunction that tracks request counts per IP using KV storage - Integrates rate limiting into the main request handler with 429 responses for exceeded limits
- Adds KV namespace configuration and a test endpoint for verification
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| backend/wrangler.jsonc | Adds KV namespace binding for rate limiting storage |
| backend/src/index.ts | Implements rate limiting logic and integrates it into the request handler |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dineshsutihar
approved these changes
Sep 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces IP-based rate limiting to the Cloudflare Worker handling
/v1/translateand/v1/explainroutes. The main goal is to protect the Gemini API from abuse and prevent excessive requests that could exhaust our quota.Changes Made:
checkRateLimitfunction using Cloudflare KV to track request counts per IP.429 Too Many Requestserror if exceeded.fetchhandler to integrate the rate limiting check before processing requests./v1/translateand/v1/explainroutes.Benefits:
Screenshots: