-
-
Save miladj3/d0c5d6c7d150c6bddcd952f3317e52af to your computer and use it in GitHub Desktop.
Simple GitHub Raw Proxy Worker
This file contains hidden or 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
export default { | |
async fetch(request) { | |
const url = new URL(request.url); | |
const path = url.pathname.replace(/^\/+/, ""); | |
const parts = path.split("/"); | |
if (parts.length < 4) { | |
return new Response("Usage: /owner/repo/branch/path/to/file.ext", { status: 400 }); | |
} | |
const [owner, repo, branch, ...filePathParts] = parts; | |
const filePath = filePathParts.join("/"); | |
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${filePath}`; | |
const resp = await fetch(rawUrl); | |
return new Response(resp.body, { | |
status: resp.status, | |
headers: resp.headers, | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment