Skip to content

Instantly share code, notes, and snippets.

@symant233
Last active June 18, 2024 14:27
Show Gist options
  • Save symant233/bac4df4514dff297dd06a6fc47f92d9f to your computer and use it in GitHub Desktop.
Save symant233/bac4df4514dff297dd06a6fc47f92d9f to your computer and use it in GitHub Desktop.
Raw content http proxy for cloudflare workers (GET only). try `https://${yourWorkerRoute}/?https://${uri}`
/**
* Cloudflare Workers Raw content fetcher
* Usage: https://${yourWorkerRoute}/?https://developer.mozilla.org
*/
addEventListener("fetch", (event) => {
const res = handleRequest(event.request)
.catch((err) => new Response(err.stack, { status: 500 }))
event.respondWith(res);
});
/**
* @param {Request} request
* { headers, method, url }
*/
async function handleRequest(request) {
const TAIL = '/?http';
let path = request.url;
let index = path.indexOf(TAIL);
while (index != -1) {
path = path.slice(index + 2);
index = path.indexOf(TAIL);
}
let res = await fetch(path);
return res;
// return new Response(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment