优化 worker.js 中的 fetch 函数,调整响应内容格式

This commit is contained in:
严浩
2025-07-15 22:49:34 +08:00
parent 96d10ab6a0
commit 7c0b455407
+7 -3
View File
@@ -2,14 +2,18 @@ export default {
async fetch(request, env, ctx) { async fetch(request, env, ctx) {
const url = new URL(request.url); const url = new URL(request.url);
console.log('url :>> ', url); console.log('url :>> ', url);
if ("/" === url.pathname) { if ('/' === url.pathname) {
return new Response(`curl -fsSL ${url.origin}/install.sh | sh - return new Response(`curl -fsSL ${url.origin}/install.sh | sh -
iwr ${url.origin}/install.ps1 -useb | iex`); iwr ${url.origin}/install.ps1 -useb | iex
pnpm config get registry
pnpm config set registry https://registry.npmmirror.com
`);
} }
let response = await fetch(`http://get.pnpm.io${url.pathname}`); let response = await fetch(`http://get.pnpm.io${url.pathname}`);
let text = await response.text(); let text = await response.text();
text = text.replace(/https:\/\/github.com/g, "https://gh-cf.oo1.dev/https://github.com"); 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 from GitHub', 'Downloading pnpm from GitHub (via Cloudflare)');
text = text.replace('Downloading pnpm', 'Downloading pnpm (via Cloudflare)'); text = text.replace('Downloading pnpm', 'Downloading pnpm (via Cloudflare)');
return new Response(text); return new Response(text);