© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•3y ago•
1 reply
LessUse

cloudflare worker not counting requests to specific **API** routes

I have a fastapi application running on render at this url: https://example.onrender.com. the application is protected by cloudflare. i have various api routes such as https://example.onrender.com/v1/xxx, https://example.onrender.com/v1/yyy, etc.

my goal is to count the number of requests made to these specific routes. to do this, i deployed a cloudflare worker that is designed to increment a counter in a cloudflare kv namespace whenever a request hits one of these api routes.

i set the worker route to
example.onrender.com/v1*
example.onrender.com/v1*
on the cloudflare dashboard. this way, it should match any of the /v1/ routes.

the issue is that my cloudflare worker does not seem to be incrementing the counter when i make requests to these routes. the worker request count on the cloudflare dashboard also does not seem to update — it remains unchanged.

my cloudflare worker script:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  // Increment count in Cloudflare KV
  let count = await myKV.get('request_count') || '0';
  count = parseInt(count) + 1;
  await myKV.put('request_count', count.toString());

  // Forward the request to your application
  const url = new URL(request.url)
  // Change this to the URL of your application
  const api_url = 'https://example.onrender.com' + url.pathname
  const api_request = new Request
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  // Increment count in Cloudflare KV
  let count = await myKV.get('request_count') || '0';
  count = parseInt(count) + 1;
  await myKV.put('request_count', count.toString());

  // Forward the request to your application
  const url = new URL(request.url)
  // Change this to the URL of your application
  const api_url = 'https://example.onrender.com' + url.pathname
  const api_request = new Request
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Worker Routes not working
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago
Cloudflare worker context persists between requests?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
Specific Worker Access in Cloudflare Team
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
10mo ago