async function handler(event) {
let req = event.request;
if(req.method === "POST") {
const reqBody = await req.text();
let encbody = encodeURI(reqBody);
let formatquery = encbody.replace('%7B%22query%22:%20%22','');
formatquery = formatquery.replace('%22%7D','');
formatquery = formatquery.replace(/\%5Cn/g,'%0A');
formatquery = decodeURI(formatquery);
const url = new URL(req.url);
url.pathname = "/v1/graphql";
url.searchParams.set("query", formatquery);
console.log("GET request URL is " + url);
req.headers.delete("Content-Type");
return await fetch(url, {
method: "GET",
backend: "origin_0",
});
}else{
return await fetch(req.url, {
backend: "origin_0",
});
}
}
addEventListener("fetch", event => event.respondWith(handler(event)));