Refactor worker.js to handle requests and modify response
This commit is contained in:
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"humao.rest-client"
|
||||
]
|
||||
}
|
10
src/request.http
Normal file
10
src/request.http
Normal file
@ -0,0 +1,10 @@
|
||||
###
|
||||
GET http://localhost:8787/
|
||||
|
||||
###
|
||||
GET http://localhost:8787/install.sh
|
||||
|
||||
###
|
||||
GET http://localhost:8787/install.ps1
|
||||
|
||||
|
@ -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