export default {
async fetch(request, env) {
const url = "db";
const response = await fetch(url);
const { contentType, result } = await gatherResponse(response);
const data = result;
// gatherResponse returns both content-type & response body as a string
async function gatherResponse(response) {
const { headers } = response;
const contentType = headers.get("content-type") || "";
return { contentType, result: await response.json() };
}
let ur2l = data[Math.floor(Math.random() * data.length)]
const aa = await fetch(ur2l.split("|")[2])
const resp = new Response((await aa.arrayBuffer()), {headers: { "content-type": aa.headers.get("content-type") || "no"}})
resp.headers.append("X-fetchedurl", ur2l.split("|")[2])
resp.headers.append("X-fetchedurlid", ur2l.split("|")[1])
resp.headers.append("X-fetchedurlname", ur2l.split("|")[0])
return resp;
}
}