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); }
1 Reply
Vero
Vero2y ago
Hey @lokiwind. I see you're new here, so welcome!! Do you want to override the method to be POST, but with fetch(request) you don't pass in the init? is that the issue?
Want results from more Discord servers?
Add your server