Last active
August 7, 2024 12:46
-
-
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}`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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