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": ${ip}|${countryCode} }); const init = { method: "POST", body: data }; return fetch(url, init); }
Was this page helpful?