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* 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
1 Reply
LessUse
LessUse12mo ago
i have waited longer than a minute and my KV store or worker request count is still not updating, the problem could be elsewhere
Want results from more Discord servers?
Add your server