Refactor worker.js to handle requests and modify response
This commit is contained in:
@ -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);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user