web / scripts /cloudflare-worker-web.js
hanbinsite's picture
docs: add Cloudflare Worker script for web frontend proxy
82371bf
Raw History Blame Contribute Delete
704 Bytes
// Cloudflare Worker - Web 前端反向代理
// 目标:www.hanbin666.top → binhugg4-web.hf.space
// 部署方式:Cloudflare Dashboard → Workers & Pages → Create Worker → 粘贴此代码
// 路由绑定:www.hanbin666.top/* 或 hanbin666.top/*
export default {
async fetch(request) {
const url = new URL(request.url);
url.hostname = "binhugg4-web.hf.space";
url.port = "443";
url.protocol = "https:";
const newRequest = new Request(url.toString(), {
method: request.method,
headers: request.headers,
body: ["GET", "HEAD"].includes(request.method) ? undefined : request.body,
redirect: "follow",
});
return fetch(newRequest);
},
};