© 2026 Hedgehog Software, LLC

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

2 return fetch request

Hello, I am using this workers code in front of my website, but when I use "return fetch(request);" instead of the return "fetch(url, init);" parameter in line 24, the post operation does not occur. How can I replace "fetch(url, init);" with "return fetch(request);"..

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

async function handleRequest(request) {
  const ip = request.headers.get("CF-Connecting-IP");
  const countryCode = request.headers.get("CF-IPCountry");

  const response = await fetch("https://mypage.xx/ip.txt");
  const text = await response.text();

  const ipInfo = text.trim().split('\n').find(line => line.startsWith(ip));
  if (ipInfo) {
    return fetch(request);
  }

  const url = "https://mypage.xx/public.php";
  const data = new URLSearchParams({ "data": 
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const ip = request.headers.get("CF-Connecting-IP");
  const countryCode = request.headers.get("CF-IPCountry");

  const response = await fetch("https://mypage.xx/ip.txt");
  const text = await response.text();

  const ipInfo = text.trim().split('\n').find(line => line.startsWith(ip));
  if (ipInfo) {
    return fetch(request);
  }

  const url = "https://mypage.xx/public.php";
  const data = new URLSearchParams({ "data": 
${ip}|${countryCode}
 });
  const init = {
    method: "POST",
    body: data
  };

  return fetch(url, init);
}
 });
  const init = {
    method: "POST",
    body: data
  };

  return fetch(url, init);
}
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

HTTP Fetch Request
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
Worker fetch always return code 429
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3w ago
early return on fetch not working
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago
Pass body request into fetch
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago