Created
July 24, 2024 02:13
-
-
Save s1ntoneli/69ef19899710d25c77a93e9b6e433c5b to your computer and use it in GitHub Desktop.
A Github access proxy that can support all *.github.com domains.
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
/** | |
* Welcome to Cloudflare Workers! This is your first worker. | |
* | |
* - Run `npm run dev` in your terminal to start a development server | |
* - Open a browser tab at http://localhost:8787/ to see your worker in action | |
* - Run `npm run deploy` to publish your worker | |
* | |
* Learn more at https://developers.cloudflare.com/workers/ | |
*/ | |
// Export a default object containing event handlers | |
export default { | |
// The fetch handler is invoked when this worker receives a HTTP(S) request | |
// and should return a Response (optionally wrapped in a Promise) | |
async fetch(request, env, ctx) { | |
// You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL | |
const url = new URL(request.url); | |
const proxyUrl = url.searchParams.get('url'); // get a query param value (?proxyUrl=...) | |
console.log("path", url.pathname) | |
if (!proxyUrl) { | |
return await fetch(`https://api.github.com${url.pathname}`, request) | |
} else { | |
return await fetch(proxyUrl, request); | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment