diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0653d56 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "humao.rest-client" + ] +} diff --git a/src/request.http b/src/request.http new file mode 100644 index 0000000..f5062f7 --- /dev/null +++ b/src/request.http @@ -0,0 +1,10 @@ +### +GET http://localhost:8787/ + +### +GET http://localhost:8787/install.sh + +### +GET http://localhost:8787/install.ps1 + + diff --git a/src/worker.js b/src/worker.js index b9effa2..7799892 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,16 +1,17 @@ -/** - * 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 default { async fetch(request, env, ctx) { - return new Response('Hello World!'); + const url = new URL(request.url); + console.log('url :>> ', url); + if ("/" === url.pathname) { + return new Response(`curl -fsSL ${url.origin}/install.sh | sh - +iwr ${url.origin}/install.ps1 -useb | iex`); + } + + let response = await fetch(`http://get.pnpm.io${url.pathname}`); + let text = await response.text(); + text = text.replace(/https:\/\/github.com/g, "https://gh-cf.oo1.dev/https://github.com"); + text=text.replace('Downloading pnpm from GitHub','Downloading pnpm from GitHub (via Cloudflare)'); + text=text.replace('Downloading pnpm','Downloading pnpm (via Cloudflare)'); + return new Response(text); }, -}; \ No newline at end of file +};