addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const urlStr = request.url
const urlObj = new URL(urlStr)
const url = urlObj.href.substr(urlObj.origin.length+1).replace("http:/","http://").replace("https:/","https://")
const headers = {}
request.headers.forEach((value,index)=>{
console.log(value,index)
if(index.indexOf("ip")!=-1 || index.indexOf("cf")!=-1) return;
headers[index]=value;
})
var selfreq=new Request(url, {
body: request.body,
headers: headers,
method: request.method,
redirect: request.redirect
})
return fetch(selfreq, { cf: { scrapeShield: false } })
}